Python Notes by Ankush Chap-08-Operators
Python Notes by Ankush Chap-08-Operators
Chapter - 08
Operators in Python
What are Operators
Types of Operators
Operators Examples
Operators in Python
Operators in Python are special symbols or keywords used to perform
operations on operands (variables and values).
Operators: These are the special symbols/keywords. Eg: + , * , /, etc.
Operand: It is the value on which the operator is applied.
Examples
Addition operator a + b
'+':
Equal operator a == b
'==':
and operator 'and': a > 10 and b <
20
Types of Operators
Python supports various types of operators, which can be broadly
categorized as:
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Identity Operators
7. Membership Operators
P y thon No te s by Ankush
Operators Cheat Sheet
Operator Description
() Parentheses
** Exponentiation
+, -, ~ Positive, Negative, Bitwise NOT
*, /, //, % Multiplication, Division, Floor Division,
Modulus
+, - Addition, Subtraction
==, !=, >, >=, <, <= Comparison operators
is, is not, in, not in Identity, Membership Operators
NOT, AND, OR Logical NOT, Logical AND, Logical OR
<<, >> Bitwise Left Shift, Bitwise Right Shift
&, ^, | Bitwise AND, Bitwise XOR, Bitwise OR
1.Arithmetic Operators
Arithmetic operators are used with numeric values to perform
mathematical operations such as addition, subtraction, multiplication,
and division.
P y thon No te s by Ankush
Precedence of Arithmetic Operators in Python:
P – Parentheses
E–
Exponentiation
M–
Multiplication D
– Division
A – Addition
S – Subtraction
3.Assignment Operators
Assignment operators are used to assign values to variables.
P y thon No te s by Ankush
4.Logical Operators
Logical operators are used to combine conditional statements.
6.Bitwise Operators
Bitwise operators perform operations on binary numbers.
P y thon No te s by Ankush
Bitwise Operators Example:
Compare each bit in these Eg:1
numbers.
010 (This is 5 in binary) a = 5 0101
1
001 (This is 3 in binary)
------- b = 3
print(a fi b) 0011
1
0001 (This is the result 5 fi 3) Output: 1 0001
of
P y thon No te s by Ankush`