You are on page 1of 6

Operators in python

Comparison operator
These operators compare the values on either side of them and decide the
relation among them. In other words comparison operator is use to compare
two values and returns TRUE or FALSE.
Operators Name
== is equal to
!= is not equal to
> Greater than
< Less than
>= Greater than and equal to
<= Less than and equal to
For Example:
• x = 2 , y = 5, z =2, a = 5
• x == y ------False, x == z ----- True
• y > z, y >=a, and y>=z -----------True
• z < y and z <= x-------------------True
• x != y ------- True, x != a -------- False
Assignment Operator
Assignment operator are used to assign values to variables.
Operator Name
+= Addition and
-= Subtraction and
*= Multiplication and
/= Division and
%= Modulus and
**= Exponent and
//= Floor Division and
For Example:
num1 = 3 and num2 = 5
num1 += num2 ------ num1 = num1 + num2 ------ num1 = 3 + 5 = 8
num1 *= num2 ------- num1 = num1 * num2 ------ num1 = 3 * 5 = 15
num2 //= num1 ------- num2 = num2 // num1 ------ num2 = 5 // 3 = 2
Thank you

You might also like