Fundamentals of Python
Introduction to Python: Python is an easy-to-learn yet powerful object-
oriented programming language. It was developed by Guido Van Rassum in
February 1991. People use Python for Competitive Programming, Web
Development, and creating software.
Python Character Set: Character set is a set of valid character sets that a
language can recognize. Python has following character set.
Letter A to Z and a to z
Digits 0 to 9
Special characters +, *, :, ( ), [ ], { }, /, = etc.
Tokens: The smallest individual unit in a program is known as a Token.
Python has following tokens.
i. Keywords: A keyword is a word having special meaning reserved by
programming language.
For example int, for, while, if, else, with, break, continue etc.
ii. Identifiers: Identifiers are the tokens in Python that are used to name
entities like variables, functions, classes, etc. These are the user-defined
names.
Rules for Naming an Identifier
• An identifier have only letters, digits and special symbol underscore ( __
). It can not have any other character.
• An identifier must begin with a letter or _. The first letter of an identifier
cannot be a digit.
• Identifiers cannot be a keyword.
iii. Literal: Literal often to referred to as constant Values. Python allows
following types of literals.
1. Numeric Literal: It belongs to any numerical value like 56, 7.8, 18 etc.
Numeric literals are two types.
a. Integer Literal: Integer Literals are whole numbers without any fractional
part.
Ex. 12, 567, 89 etc.
b. Floating Point Literals: Floating Literals are also called Real literals are
numbers having fractional parts.
Ex. 15.67, 54.74, 89.0 etc.
2. String Literal: A string literal is a sequence of characters surrounded by
single, double or triple quotes.
String literals are two types.
a. Single-line string: Group of characters in single line surrounded by single
or double quotes.
Ex. “Python Language”, ‘Python Language’
b. Multi-line string: Group of characters in multi-line surrounded by triple
quotes.
Ex. ‘’’Python
Language’’
3. Boolean Literal: It is used to represent one of two values True or False.
4. Special Literal: The special literal None is use to indicate absence of value.
iv. Operator: Operators are tokens that trigger some computation / action
when applied to operands( Variable or Literals).
In Python following types of operators.
a. Arithmetic Operators
Symbol Example Result
+ (Addition) 7+5 12
- (Subtraction) 7–5 2
* (Multiplication) 7*2 14
/ (Division) 7/2 3.5
% (Remainder) 7%2 1
** (Exponent) 2 ** 3 (e.g. 2 * 2 * 2) 8
// (Floor Division) 7 // 2 3.0
b. Relational Operators
Symbol Example Result
> (Greater than) 7>4 True
< (Less than) 7<4 False
>= (Greater than equal) 12 >= 12 True
<= (Less than equal) 11 <= 15 True
== (Equal to) 12 == 17 False
!= (Not equal to) 12 != 17 True
c. Assignment Operators
Symbol Example Result
= (Assign values) a=5 Value of a is 5
+= (Add and assign) a += 5 (Same as a = a + 5) 5 increase in a
-= (Subtract and assign) a -= 5 (Same as a = a - 5) 5 decrease from a
Other operators are *=, /=, %=, **=, //=
d. Logical Operators
Symbol Example Result
and 7>5 and 12<9 False
or 7>5 or 12<9 True
not not (7 > 10) True
e. Membership Operators
Symbol Example Result
in 4 in (5. 8, 9) False
not in 4 not in (5, 8, 9) True
f. Identify Operators: is and not is