Operators: Team Emertxe
Operators: Team Emertxe
Team Emertxe
Arithmetic
OPERATORS
Arithmetic
Operator Example Result
+ a+b 18
- a-b 8
* a*b 65
/ a/b 2.6
% a%b 3
** a ** b 371293
// a // b 2
= a = b = 1
+=
-+ Example-2:
*+ a = 1; b = 1
/=
%= Example-3:
**=
a, b = 1, 2
//=
n = 10
print(-n)
Example-2:
num = -10
num = -num
print(num)
OPERATORS
Relational
Operator Example Result
== a == b False
!= a != b True
Example-2:
and a and b 2
or a or b 1
Example-1: Example-2:
if (a < b and b < c): if (a > b or b < c):
print("Yes") print("Yes")
else: else:
print("No") print("No")
or a or b True
Example-1:
print(a and b)
print(a or b)
print(not a)
OPERATORS
Bitwise
If a = 10(0000 1010), b = 11(0000 1011)
Operator Example Result
~ ~a 1111 0101(-11)
| a | b 0000 1011(11)
^ a ^ b 0000 0001(1)
Example-1:
names = ["Ram", "Hari", "Thomas"]
for i in names:
print(i)
Example-2:
postal = {"Delhi": 110001, "Chennai": 600001, "Bangalore": 560001}
Operator Description
Example-1:
a = [1, 2, 3, 4]
b = [1, 2, 3, 4]
if (a == b):
print("Objects are same")
else:
print("Objects are
not same")
OPERATORS
Precedence & Associativity
Operator Name
(expressions...), [expressions...], {key: Binding or tuple display, list display, dictionary
value...}, {expressions...} display, set display
x[index], x[index:index], x(arguments...), Subscription, slicing, call, attribute reference
x.attribute
** Exponentiation
^ Bitwise XOR
| Bitwise OR
in, not in, is, is not, <, <=, >, >=, !=, == Comparisons, including membership tests and identity
tests
not Boolean not
or Boolean or
Example-2:
import math as m
x = m.sqrt(16)
Example-3:
from math import sqrt
x = sqrt(16)
Example-4:
from math import sqrt, factorial
x = sqrt(16)
y = factorial(5)
THANK YOU