Used to assign values to variables (sometimes with an operation).
Operator
Example
Equivalent To
=
x = 5
assigns value
+=
x += 3
x = x + 3
-=
x -= 2
x = x - 2
*=
x *= 4
x = x * 4
/=
x /= 2
x = x / 2
//=
x //= 3
x = x // 3
%=
x %= 2
x = x % 2
**=
x **= 3
x = x ** 3
Example:
x = 10
x += 5 # x = 15
x *= 2 # x = 30
print(x)
4. Logical Operators
Used for logical conditions (returns True/False).
Operator
Example
Meaning
and
(x > 5 and y < 10)
True if both conditions are True
or
(x > 5 or y < 10)
True if at least one condition is True
not
not(x > 5)
Reverses result
Example:
x, y = 8, 3
print(x > 5 and y < 5) # True
print(x > 10 or y < 5) # True
print(not(x > 5)) # False
5. Identity Operators
Used to check if two objects are the same in memory.
Operator
Example
Meaning
is
x is y
True if same object
is not
x is not y
True if not same object
Example:
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a is b) # True (same object in memory)
print(a is c) # False (same content, but different objects)
print(a == c) # True (values are equal)
6. Membership Operators
Used to check if a value is inside a sequence (list, tuple, string, etc.).
Operator
Example
Meaning
in
"a" in "apple"
True
not in
"z" not in "apple"
True
Example:
fruits = ["apple", "banana", "cherry"]
print("apple" in fruits) # True
print("mango" not in fruits) # True
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Example:
1. Arithmetic Operators
Used for basic math operations.
+10 + 515-10 - 55*10 * 550/10 / 52.0(always float)//10 // 33(drops decimal)%10 % 31**2 ** 38Example:
2. Comparison (Relational) Operators
Used to compare two values → return
TrueorFalse.==5 == 5!=5 != 3>5 > 3<5 < 3>=5 >= 5<=3 <= 5Example:
3. Assignment Operators
Used to assign values to variables (sometimes with an operation).
=x = 5+=x += 3x = x + 3-=x -= 2x = x - 2*=x *= 4x = x * 4/=x /= 2x = x / 2//=x //= 3x = x // 3%=x %= 2x = x % 2**=x **= 3x = x ** 3Example:
4. Logical Operators
Used for logical conditions (returns
True/False).and(x > 5 and y < 10)or(x > 5 or y < 10)notnot(x > 5)Example:
5. Identity Operators
Used to check if two objects are the same in memory.
isx is yis notx is not yExample:
6. Membership Operators
Used to check if a value is inside a sequence (list, tuple, string, etc.).
in"a" in "apple"not in"z" not in "apple"Example:
7. Bitwise Operators
Work at the bit level (binary representation).
&5 & 3^5 ^ 3~~5<<5 << 1>>5 >> 1Example:
Summary
+ - * / % // **)== != > < >= <=)= += -= ...)and, or, not)is, is not)in, not in)& | ^ ~ << >>)