1
+ # Arithmetic operators
2
+ x = 10
3
+ y = 5
4
+ print ("Arithmetic Operators:" )
5
+ print ("x + y =" , x + y )
6
+ print ("x - y =" , x - y )
7
+ print ("x * y =" , x * y )
8
+ print ("x / y =" , x / y )
9
+ print ("x // y =" , x // y )
10
+ print ("x % y =" , x % y )
11
+ print ("x ** y =" , x ** y )
12
+
13
+ # Comparison operators
14
+ print ("\n Comparison Operators:" )
15
+ print ("x > y is" , x > y )
16
+ print ("x < y is" , x < y )
17
+ print ("x == y is" , x == y )
18
+ print ("x != y is" , x != y )
19
+ print ("x >= y is" , x >= y )
20
+ print ("x <= y is" , x <= y )
21
+
22
+ # Logical operators
23
+ a = True
24
+ b = False
25
+ print ("\n Logical Operators:" )
26
+ print ("a and b is" , a and b )
27
+ print ("a or b is" , a or b )
28
+ print ("not a is" , not a )
29
+
30
+ # Bitwise operators
31
+ m = 10 # 1010 in binary
32
+ n = 4 # 0100 in binary
33
+ print ("\n Bitwise Operators:" )
34
+ print ("m & n is" , m & n )
35
+ print ("m | n is" , m | n )
36
+ print ("m ^ n is" , m ^ n )
37
+ print ("~m is" , ~ m )
38
+ print ("m << 2 is" , m << 2 )
39
+ print ("m >> 2 is" , m >> 2 )
40
+
41
+ # Assignment operators
42
+ z = 15
43
+ print ("\n Assignment Operators:" )
44
+ z += 5
45
+ print ("z += 5, z is" , z )
46
+ z -= 5
47
+ print ("z -= 5, z is" , z )
48
+ z *= 2
49
+ print ("z *= 2, z is" , z )
50
+ z /= 2
51
+ print ("z /= 2, z is" , z )
52
+ z %= 5
53
+ print ("z %= 5, z is" , z )
54
+ z //= 2
55
+ print ("z //= 2, z is" , z )
56
+ z **= 3
57
+ print ("z **= 3, z is" , z )
58
+
59
+ # Identity operators
60
+ list1 = [1 , 2 , 3 ]
61
+ list2 = [1 , 2 , 3 ]
62
+ print ("\n Identity Operators:" )
63
+ print ("list1 is list2:" , list1 is list2 )
64
+ print ("list1 is not list2:" , list1 is not list2 )
65
+
66
+ # Membership operators
67
+ print ("\n Membership Operators:" )
68
+ print ("1 in list1:" , 1 in list1 )
69
+ print ("4 not in list1:" , 4 not in list1 )
0 commit comments