Professional Documents
Culture Documents
Python Operators
Python Operators
1
Operator and Operand
In other words, operators are constructs that can manipulate values of operands.
In the example above, 6 and 8 are considered operands while the + is the operator.
2
Types of Operators
Arithmetic Operators
Assignment Operators
Comparison (Relational) Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
3
Arithmetic Operators
4
Operator Name Description Syntax
5
Assignment Operators
6
Operator Description Syntax
Assign value of the right side of expression to
= Z=X+Y
left side operand
Add right side operand with left side operand
+= Z+=X
and then assign to left operand
Subtract right operand from left operand and
-= Z-=X
then assign to left operand
Multiply right operand with left operand and
*= Z*=X
then assign to left operand
Divide left operand with right operand and
/= Z/=X
then assign to left operand
7
Comparison Operators
8
Operator Name Description Syntax
9
Logical Operators
10
Operator Name Description Syntax
11
Exercise One
12
Bitwise Operators
& | ^ ~ << >>
The integers are first converted to binary and then operations are
performed on bit by bit.
13
Membership Operators
in not in
is is not
15
Operator Precedence
Highest
Lowest
16
Exercise Two
Evaluate the following.
a. 16*20+4
b. 102-41//6
c. 20.0*12.0-4
d. 9.2*54**4
e. 9%5
f. 2**12+4+23-7%8
g. 124//8*6+234
h. 5**6+9-12
17
Lesson Summary
18
Thank You.
19