|
| 1 | +#OPERATORS |
| 2 | + |
| 3 | +#MATHEMATICAL OPERATORS |
| 4 | +# Sum |
| 5 | +a= 10 |
| 6 | +b = 22 |
| 7 | +print ("Sum is:", a+b) |
| 8 | +# Subtract |
| 9 | +a=10 |
| 10 | +b=22 |
| 11 | +print ("Difference is", a-b) |
| 12 | +# Multiplication |
| 13 | +a=10 |
| 14 | +b=22 |
| 15 | +print ("Product is:", a*b) |
| 16 | +# Division (Ans in FLoat) |
| 17 | +a=10 |
| 18 | +b=22 |
| 19 | +print ("Division is:",a/b) |
| 20 | +# Integer Division (Ans in int) |
| 21 | +a=10 |
| 22 | +b=22 |
| 23 | +print ("Integer Division is:" , a//b) |
| 24 | +# Notation (A to the Power B i.e.a^b) |
| 25 | +a=10 |
| 26 | +b=22 |
| 27 | +print ("Raised to the Power is:", a**b) |
| 28 | +# Modulus (remainder i.e. 2/2 R=0 or 3/2 R=1) |
| 29 | +a=10 |
| 30 | +b=22 |
| 31 | +print ("Remainder is:", a%b) |
| 32 | + |
| 33 | +#MEMBERSHIP OPERATORS (Ans in True or False) |
| 34 | +# Not In |
| 35 | +x = ["wasim", "lubaid", "shahroz", "usman", "faisal", "farhan"] |
| 36 | +print("parkash" not in x) |
| 37 | +# In |
| 38 | +x = ["wasim", "lubaid", "shahroz", "usman", "faisal", "farhan"] |
| 39 | +print("faisal" in x) |
| 40 | + |
| 41 | +print("") |
| 42 | + |
| 43 | +#IDENTITY OPERATOR (True/False) |
| 44 | +# is not |
| 45 | +x = ["ahmed", "bashir"] |
| 46 | +y = ["ahmed", "bashir"] |
| 47 | +z = x |
| 48 | +print(x is not z) |
| 49 | +print(x is not y) |
| 50 | +print(x!=y) |
| 51 | +# is |
| 52 | +print(x is z) |
| 53 | +print(x is y) |
| 54 | +print(x == y) |
| 55 | + |
| 56 | +print("") |
| 57 | +#LOGICAL OPERATOR (True/False) |
| 58 | +# And (If both are True Then it is true) |
| 59 | +x = 15 |
| 60 | +print(x > 14 and x < 20) |
| 61 | +# Or (If both are False then it is False)(True if any one is True) |
| 62 | +x = 25 |
| 63 | +print(x >23 or x < 24) |
| 64 | +#Not (Negation) |
| 65 | +x = 35 |
| 66 | +print(not(x > 33 and x < 40)) |
| 67 | + |
| 68 | +# COMPARISON OPERATOR |
| 69 | +# < |
| 70 | +x = 20 |
| 71 | +y = 15 |
| 72 | +print("X is Less than Y:",x < y) |
| 73 | +# <= |
| 74 | +x = 20 |
| 75 | +y = 15 |
| 76 | +print("X is Less than or equal to Y:",x <= y) |
| 77 | +# > |
| 78 | +x = 20 |
| 79 | +y = 15 |
| 80 | +print("X is Greater than Y:",x > y) |
| 81 | +# >= |
| 82 | +x = 20 |
| 83 | +y = 15 |
| 84 | +print("X is Greater than or equal to Y:",x >= y) |
| 85 | +# == |
| 86 | +x = 20 |
| 87 | +y = 15 |
| 88 | +print("X is equal to Y:", x == y) |
| 89 | +# =! |
| 90 | +x = 20 |
| 91 | +y = 15 |
| 92 | +print("X is not equal to Y:", x != y) |
| 93 | + |
| 94 | + |
| 95 | +#ASSIGNMENT OPERATORS |
| 96 | +# + |
| 97 | +x = 5 |
| 98 | +x += 3 |
| 99 | +print(x) |
| 100 | +# - |
| 101 | +x = 5 |
| 102 | +x -= 3 |
| 103 | +print(x) |
| 104 | +# * |
| 105 | +x = 5 |
| 106 | +x *=3 |
| 107 | +print(x) |
| 108 | +# / |
| 109 | +x = 5 |
| 110 | +x /= 3 |
| 111 | +print(x) |
| 112 | +# % |
| 113 | +x = 5 |
| 114 | +x %= 3 |
| 115 | +print(x) |
| 116 | +# // |
| 117 | +x = 5 |
| 118 | +x //= 3 |
| 119 | +print(x) |
| 120 | +# ** |
| 121 | +x = 5 |
| 122 | +x **= 3 |
| 123 | +print(x) |
| 124 | + |
| 125 | +print("") |
| 126 | +# BITWISE OPERATORS |
| 127 | + |
| 128 | +# Bitwise And |
| 129 | +x = 5 |
| 130 | +x &= 3 |
| 131 | +print(x) |
| 132 | +# Bitwise Or |
| 133 | +x = 5 |
| 134 | +x |= 3 |
| 135 | +print(x) |
| 136 | +# Bitwise XOR |
| 137 | +x = 5 |
| 138 | +x ^= 3 |
| 139 | +print(x) |
| 140 | +# Shift Right |
| 141 | +x = 5 |
| 142 | +x >>= 3 |
| 143 | +print(x) |
| 144 | +# Shift Left |
| 145 | +x = 5 |
| 146 | +x <<= 3 |
| 147 | +print(x) |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +#IN AND NOT IN |
| 153 | +x = "Good Morning To Everyone In Class,Sec A " |
| 154 | +for i in x: |
| 155 | + if i in 'aeiouAEIOU': |
| 156 | + print(i) |
| 157 | + |
| 158 | +x = "Good Morning To Everyone In Class,Sec A " |
| 159 | +for i in x: |
| 160 | + if i in 'aeiouAEIOU': |
| 161 | + print(i, "\t", x.index(i)) |
| 162 | + |
| 163 | +x = "Good Morning To Everyone In Class,Sec A " |
| 164 | +for i in x: |
| 165 | + if i not in 'aeiouAEIOU': |
| 166 | + print(i, "\t", x.index(i)) |
0 commit comments