Professional Documents
Culture Documents
Python Notes: Developed By:-Guido Van Rossum in February 1991
Python Notes: Developed By:-Guido Van Rossum in February 1991
Python Notes: Developed By:-Guido Van Rossum in February 1991
2. identifiers (Names)
Tokens 3. Literals
4. Operators
5. Punctuators
keywords
False assert elif for in or while
None break else from is pass with
True class expect global lambda raise yield
•HAVING SPECIAL MEANING
RESERVED BY and continue finally if nonlocal return
PROGRAMMING LANGUAGE
as def del import not try
•AND MUST NOT TO BE USED
AS IDENTIFIERS NAMES
Identifiers (names)
identifiers are used as the general terminology for the names
given to different part of program viz. variables, object, classes,
functions, list, dictionaries etc.
Identifiers rules
1. Identifier is an arbitrarily long sequence of letters and
digits
2. The first character must be a letter; the Underscore(_)
counts as a letter.
3. Upper and lower-case letters are different. All characters Valid example of identifier Invalid example of identifier
are significant.
4. The digits 0-9 can be part of the identifier expect first
character. Myfile, DATE9_7_7_77, DATA-REC (Contains hyphen (-))
5. Identifiers are unlimited in length. Case is significant i.e., Z2T0Z9, MYFILE, 23LCCT (starting with digit)
python is case sensitive. _DS, _PYTHON_3L, _CHK, Break (reserved keyword)
6. An identifier must not be a keyword of python. FILE123 My.file (contain special character dot(.)
7. Identifier can't be contain any special character expect for
underscore(_).
Literals/Values
Literals are the data items that a fixe value.
1. String Literals
2. Numeric Literals
3. Boolean Literals
4. Special Literal NONE
5. Literal Collections
String Literals
Types of String
1. Single-line String
2. Multi-Line String
1. Single-Line String
Example:
a=‘Hello World’
2. Multi-Line String
a) By adding a backslash at the end of normal single-
quote/double-quote string
Example: a= ‘hello \
world’
b) By adding the text in triple quotation marks. (No
backslash needed at the end of line).
Example: a=‘ ‘ ‘ Hello
world
Python’ ’ ’
Numeric Literals
Float (floating point real values) Float represent real number and are
written with a decimal point dividing the
integer and fractional parts
Complex (complex numbers) are the form of a+bJ, where a & b are
floats and J or j represents . a is real part of
number and b is imaginary part.
• Integer Literals are whole numbers without any fractional part. It may
contains either (+) or (-) sign. Number with no sign is assumed to be
positive
Integer Octal Integer Literals: sequence of digit starting with 0o(digit zero is
followed by letter o )is to be taken an octal integer,
Floating
parts
1. Fractional form : A real literals in fractional form consists of signed or
unsigned digits including a decimals point between digits
point 2. Exponent Form: A real literal in exponent form consists of two parts:
mantissa and exponent.
Literals e.g. 5.8 can be written as 0.58x10^1 = 0.58E01, where mantissa part is 0.58 and
exponent part is 0
Boolean Literal
A Boolean literal in python is used to represent one of the two Boolean
values i.e., True or False
Special Literal NONE
Python has one special literal, which is NONE literal is used to
indicate absence of value. It is also used to indicate the end of list in
Python.
Note: Python support literal collection also such as tuples and list
etc. but covering these here would make the discussion too complex
for the beginning.
• Operators are tokens that trigger some
computation/ action when applied to
variables and other objects in an expression.
• Variables and object to which the
Operators computation is applied, are called operands,
• Unary Operators
• Binary Operators
• Arithmetic operators
• Bitwise operators
• Shift operators
• Identity operators
• Relational operators
• Logical operators
Unary Operators
• Unary operators are those that require one operand
to operate upon.
+ (Unary Plus)
- (Unary minus)
~ (Bitwise complement)
Not (logical negation)
Binary Operators
Binary operators are those operators that require two operands to
operate upon.
Arithmetic operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder/ Modulus
** exponent (raise to power)
// Floor division
Bitwise operators:
& Bitwise AND
^ Bitwise exclusive OR (XOR)
| Bitwise OR
Shift Operators:
<< Shift left
>> Shift right
Identity Operators:
Is is the identity same ?
Is not is the identity not same ?
Relational Operator
< Less than
< Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to
Logical operators
and Logical AND
or Logical OR
Membership Operators
In Whether variable in sequence
not in Whether variable not in sequence
Assignment Operators
= Assignment
/= Assign quotient
+= Assign sum
*= Assign product
%= Assign remainder
-= Assign difference
**= Assign Exponent
//= Assign Floor division
Punctuators
Punctuators are symbols that are used in programming languages to organize
programming-sentence structure, and indicates the rhythm and emphasis of
expressions, statements, and program structure
e.g. ‘ “ # \ ( ) [ ] { } @ , : ` =