-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython operators.py
166 lines (150 loc) · 2.3 KB
/
Python 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
#OPERATORS
#MATHEMATICAL OPERATORS
# Sum
a= 10
b = 22
print ("Sum is:", a+b)
# Subtract
a=10
b=22
print ("Difference is", a-b)
# Multiplication
a=10
b=22
print ("Product is:", a*b)
# Division (Ans in FLoat)
a=10
b=22
print ("Division is:",a/b)
# Integer Division (Ans in int)
a=10
b=22
print ("Integer Division is:" , a//b)
# Notation (A to the Power B i.e.a^b)
a=10
b=22
print ("Raised to the Power is:", a**b)
# Modulus (remainder i.e. 2/2 R=0 or 3/2 R=1)
a=10
b=22
print ("Remainder is:", a%b)
#MEMBERSHIP OPERATORS (Ans in True or False)
# Not In
x = ["wasim", "lubaid", "shahroz", "usman", "faisal", "farhan"]
print("parkash" not in x)
# In
x = ["wasim", "lubaid", "shahroz", "usman", "faisal", "farhan"]
print("faisal" in x)
print("")
#IDENTITY OPERATOR (True/False)
# is not
x = ["ahmed", "bashir"]
y = ["ahmed", "bashir"]
z = x
print(x is not z)
print(x is not y)
print(x!=y)
# is
print(x is z)
print(x is y)
print(x == y)
print("")
#LOGICAL OPERATOR (True/False)
# And (If both are True Then it is true)
x = 15
print(x > 14 and x < 20)
# Or (If both are False then it is False)(True if any one is True)
x = 25
print(x >23 or x < 24)
#Not (Negation)
x = 35
print(not(x > 33 and x < 40))
# COMPARISON OPERATOR
# <
x = 20
y = 15
print("X is Less than Y:",x < y)
# <=
x = 20
y = 15
print("X is Less than or equal to Y:",x <= y)
# >
x = 20
y = 15
print("X is Greater than Y:",x > y)
# >=
x = 20
y = 15
print("X is Greater than or equal to Y:",x >= y)
# ==
x = 20
y = 15
print("X is equal to Y:", x == y)
# =!
x = 20
y = 15
print("X is not equal to Y:", x != y)
#ASSIGNMENT OPERATORS
# +
x = 5
x += 3
print(x)
# -
x = 5
x -= 3
print(x)
# *
x = 5
x *=3
print(x)
# /
x = 5
x /= 3
print(x)
# %
x = 5
x %= 3
print(x)
# //
x = 5
x //= 3
print(x)
# **
x = 5
x **= 3
print(x)
print("")
# BITWISE OPERATORS
# Bitwise And
x = 5
x &= 3
print(x)
# Bitwise Or
x = 5
x |= 3
print(x)
# Bitwise XOR
x = 5
x ^= 3
print(x)
# Shift Right
x = 5
x >>= 3
print(x)
# Shift Left
x = 5
x <<= 3
print(x)
#IN AND NOT IN
x = "Good Morning To Everyone In Class,Sec A "
for i in x:
if i in 'aeiouAEIOU':
print(i)
x = "Good Morning To Everyone In Class,Sec A "
for i in x:
if i in 'aeiouAEIOU':
print(i, "\t", x.index(i))
x = "Good Morning To Everyone In Class,Sec A "
for i in x:
if i not in 'aeiouAEIOU':
print(i, "\t", x.index(i))