Operators
Arithmetic Operators
Comparison Operators
Logical Operators
Assignment Operators
Binary Operators
Identity Operators
Membership Operators
Arithmetic Operators
Addition Operator ( + )
Subtraction Operator ( - )
Multiplication Operator ( * )
Division Operator ( / )
Modulas Operator ( % )
Floor Division ( // )
Exponent Operator ( ** )
Example 1:
Addition of 10 and 3 is 13.
hello world
[4, 5, 6, 1, 2, 3]
('one', 'two', 'three', 'four', 'five', 'six')
Example 2:
-40
TypeError Traceback (most recent call last)
in () 8 l1 = [ 1,2,3] #list does not support subtraction operation 9 l2 = [ 4,5,6] ---> 10 print(l1-l2)
TypeError: unsupported operand type(s) for -: 'list' and 'list'
Example 3:
1060
Hello_World Hello_World Hello_World Hello_World Hello_World Hi Hi Hi
[1, 2, 3, 1, 2, 3, 1, 2, 3]
TypeError Traceback (most recent call last)
in () 11 print(l13) #returns list 3 times 12 l2 = [ 4,5,6] ---> 13 print(l1l2) # does not support multiplication
TypeError: can't multiply sequence by non-int of type 'list'
Example 4:
4.416666666666667
5
4
Example 5:
125
Comparison Operators
Less Than ( < )
Less Than Equals To ( <= )
Greater Than ( > )
Greater Than Equals To ( >= )
Equals To Equals To ( == )
Not Equals To ( != )
Example 6:
6 < 8 True
8 < 6 False
6 <= 6 True
6 <= 3 False
5 > 6 False
6 > 5 True
6 >= 6 True
6 >= 5 True
6 == 6 True
6 == 7 False
6 != 6 False
6 != 7 True
Logical Operators
and
or
not
Negative/Positive integers are true, 0 is false
And
If x is false, return x
else return y
Eg:
False
-3
0
0
0
Or
If x is false, return y
else x
Example 7:
False
True
True
0
10
False
Example 8:
X Y and or
True True True True
True False False True
False True False True
False False False False
Example 9:
X not
True False
False True
Assignment Operators
Example 10:
something
Example 11:
14.0
Example 12:
13
8 7 hi hello how are you
Example 13:
6 5
10 -2 60
Membership Operator
Example 14:
Pattern Found in step 1
True
False
Example 15:
l2 found in l1
Example 16:
Enter a number : 324
Number matched
Identity Operator
Example 17:
True
False
Both are different
Last updated
Was this helpful?