-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOperators_.py
131 lines (109 loc) · 3.62 KB
/
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Arithmetic Operator
# Assignment Operator
# Comparison Operator
# Logical Operator
# Identity Operator
# Membership Operator
# Bitwise Operator
# Arithmetic Operator : helps in numerical calculations
print("Arithmetic Operators :")
print("5 + 6 is",5+6)
# Output : 5 + 6 is 11
print("5 - 6 is",5-6)
# Output : 5 - 6 is -1
print("5 * 6 is",5*6)
# Output : 5 * 6 is 30
print("5 / 6 is",5/6)
# Output : 5 / 6 is 0.8333333333333334
# // Gives floor division
print("5 // 6 is",5//6) # It divide and give only Integer part
# Output : 5 // 6 is 0
print("15 // 6 is",15//6)
# Output : 15 // 6 is 2
# Power operator
print("5 ** 3 is",5**3)
# Output : 5 ** 3 is 125
# Modulus/Remainder Operator
print("5 % 3 is",5%3)
# Output : 5 % 3 is 2
#### Assignment Operator : to assign values
print("Assignment Operators :")
x = 5
print(x) # Output : 5
x += 7 # x = x + 7
print(x) # Output : 12
x = 5
print(x) # Output : 5
x -= 7 # x = x - 7
print(x) # Output : -2
x = 5
print(x) # Output : 5
x *= 7 # x = x * 7
print(x) # Output : 35
x = 5
print(x) # Output : 5
x /= 7 # x = x / 7
print(x) # Output : 0.7142857142857143
# Other Operators : '%=' ,'**=', etc. Try Out
### Comparison Operators
print("Comparison Operators :")
i = 5
print(i == 5) # Output : True
i = 8
print(i == 5) # Output : False
print(i != 5) # Output : True
print(i > 5) # Output : True
print(i < 5) # Output : False
print(i >= 5) # Output : True
print(i <= 5) # Output : False
#### Logical Operators :
print("Logical Operators :")
# and, or ,not
a = True
b = False
print(a and a) # Output : True
print(a and b) # Output : False
print(a or b) # Output : True
# not give opposite bool value
print(not b) # Output : True
#### Identity Operators :
print("Identity Operators :")
print(a is not b) # Output : True
print(5 is not 5) # Output : False
print(5 is 5) # Output : True
#### Membership Operators :
print("Membership Operators :")
list = [3,3,2,2,39,33,35,32]
print(32 in list) # Output : True
print(324 in list) # Output : False
print(324 not in list) # Output : True
##### Bitwise Operator :
print("Bitwise Operators :")
# Binary
# 0 - 00
# 1 - 01
# 2 - 10
# 3 - 11
# AND bitwise operator
print(0 & 1) # Output : 0
# OR bitwise operator
print(0 | 1) # Output : 1
print(2 & 3 ) #Output : 2
##### Some Bitwise Operators and Description :
#################################################################################
# Operator # Description #
#################################################################################
# & AND # Sets each bit to 1 if both bits are 1 #
#################################################################################
# | OR # Sets each bit to 1 if one of two bits is 1 #
#################################################################################
# ^ XOR # Inserts a double character in the text a that point. #
#################################################################################
# ~ NOT # Inserts a single quote character in the text at that point. #
#################################################################################
# << Zero fill # Shift left by pushing zeros in from the right, #
# left shift # and let the leftmost bits fall off #
#################################################################################
# >> Signed # Shift right by pushing copies of the leftmost bit #
# right shift # from the left and let the rightmost bits fall off. #
#################################################################################