-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.py
executable file
·195 lines (143 loc) · 3.2 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#[Arthmetic operators]
#addition
x = 2
y = 5
z = x + y
print(z)
#subtraction
x = 7
y = 5
z = x + y
print(z)
#multiplication
x = 2
y = 3
z = x * y
print(z)
#division
x = 8
y = 2
z = x / y
print(z)
#modules
x = 7
y = 3
z = x / y
print(z)
#exponentiation
x = 2
y = 3
z = x ** y #2*2*2
print(z)
#floor division
x = 5
y = 2
z = x // y
print(z)
#[Assignment Operators]
#Assignment operators are used to assign values to variables
# [=] : [x = 5] : [x = 5]
x = 3
print(x)
# [+=]: [x+= 5] : [x = x + 5]
x = 4
x += 5
print(x)
# [-=]: [x-= 5] : [x = x - 5]
x = 4
x -= 2
print(x)
# [*=]: [x*= 5] : [x = x * 5]
x = 4
x *= 2
print(x)
# [/=]: [x/= 5] : [x = x / 5]
x = 10
x /= 2
print(x)
x = 5
x %= 3
print(x)
x = 5
x //= 3
print(x)
x = 6
x **= 3
print(x)
x = 14
x &= 7
print(x)
# Python Comparison Operators
#Comparison operators are used to compare two value
x = 6
y = 5
print(x == y) # equall to
x = 7
y = 6
print(x != y) # not equal to
x = 6
y = 7
print(x > y) #greater then
x = 9
y = 10
print(x < y) # less then
x = 3
y = 4
print(x <= y)# less then or equal to
x = 8
y = 7
print(x >= y) # greater then or equal to
#Python Logical Operators
#Logical operators are used to combine conditional statements.
# And Opertors
# return true if both statement are true
x = 4
print(x > 6 and x < 5) #return false because 4 is less then 6 AND 4 is less then 5
#Or Operators
# return true if one ot the statement is true
x = 5
print(x > 4 or x < 3)
# return true because one of the conditions are true 5 is grater then 4
# OR 5 is not less then 3
#NOT Operators
#Reverse the result, return false if the result is true
x = 10
print(not(x > 7 and x < 15))
#Python Identity Operators
#Identity operators are used to the object , not if they are equal,
# but if they are actually the same object, with the same memory location
# is Operators
#Return true if both variables are the same object
x = [1,2,3]
y = [1,2,3]
z = x
print(x is y)
# return False because x is not the same object as y, even if they have same content
print(x is z)
#return True because z is the same object as x
print(x == y)
#to demonsatrate the different between "is" and "==" :
# this comparison return True because x is equal to y
#IS NOT Operators
# return true if both variables are not the same object
x = [1,2,3]
y = [1,2,3]
z = x
print(x is not z)
#return false because z is the same object as z
print(x is not y)
#return true because x is not the same object as y, even they have the same contrnt
print(x!=y)
# to demonstrate The difference between "is not" and "!=" :
# This comparison return false because x is equal to y
#Python membership Operators
#membership operators are used to test if a sequence is presented in an object
#In Operators
# return True if a sequence with the specified value is present in the object
x = [1,2,3]
print( 1 in x)
#return true because a sequence with the value 1 is in the list
#NOT IN Operators
#return true if a sequence with the specified values is not present in the object
x = [1,2,3]
print(not(6 in x))