1+ # Operators:- signs or keywords used to perform specific operation on multiple values or variables.
2+ # Types of Operators:-
3+ # Arithmetic Operators- +, -, *, /, **, //, %
4+ # Comparison Operators- <, >, <=. >=, ==, !=
5+ # Assignment Operators- =, +=, -=, *=, %=
6+ # Logical Operators- AND, OR, NOT
7+ # Bitwise Operators- &, |, <<, >>, -, ^
8+
9+ # Arithmetic Operators
10+ a = 3
11+ b = 4
12+ c = 6
13+ print (a + b , " " , a - b , " " , a * b , " " , c / b , " " , b ** a , " " , c // b , " " , c % b )
14+
15+ x = "Lord "
16+ y = "Voldemort "
17+
18+ # Concatenation of Strings
19+ z = x + y
20+ print (z )
21+
22+ # Replication of String
23+ print (z * a )
24+
25+ # Comparison Operators
26+
27+ print (a > b , " " , a < b , " " , a == b , " " , a != b , " " , a >= b , " " , a <= b )
28+
29+ # 'is' vs '=='
30+
31+ a , b = 3 , 3 # Constant Immutable
32+ x , y = [1 , 2 , 3 ], [1 , 2 , 3 ]
33+ print ( a == b , " " , a is b )
34+ print ( x == y , " " , x is y )
35+
36+ # Assignment Operators
37+
38+ d = 16
39+ print (d )
40+ a += 3
41+ print ( a )
42+ b -= 2
43+ print ( b )
44+ c *= 2
45+ print ( c )
46+ c %= 5
47+ print ( c )
48+ a /= 2
49+ print ( a )
50+
51+ # Logical Operators
52+
53+ if ( a > 1 and b == 2 ):
54+ print (" And is working" )
55+
56+ if ( a > 1 or b < 2 ):
57+ print (" If is working" )
58+
59+ if (not ( a < 1 and b > 2 )):
60+ print (" Not is working" )
61+
62+ # Bitwise Operators
63+
64+ x = 5 # Binary: 0101
65+ y = 3 # Binary: 0011
66+ result = x & y # Binary: 0001
67+ print (result )
68+ x = 5 # Binary: 0101
69+ y = 3 # Binary: 0011
70+ result = x | y # Binary: 0111
71+ print (result )
72+ x = 5 # Binary: 0101
73+ y = 3 # Binary: 0011
74+ result = x ^ y # Binary: 0110
75+ print (result )
76+ x = 5 # Binary: 0101
77+ result = ~ x # 2's complement
78+ print (result )
79+ x = 5 # Binary: 0101
80+ result = x << 2
81+ print (result )
82+ x = 5 # Binary: 0101
83+ result = x >> 2 # Binary: 0001
84+ print (result )
0 commit comments