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