Python Operators
Python Operators
🟦 ASSIGNMENT OPERATORS
Operator Type Meaning / Name Why / When To Use Example
Assign a value to a
= Assignment Assign value x=5
variable
Add to current value x += 3 → x =
+= Assignment Add and assign
and assign x+3
Subtract and Subtract from value and x -= 2 → x = x-
-= Assignment
assign assign 2
Multiply and Multiply value and x *= 2 → x =
*= Assignment
assign assign x*2
/= Assignment Divide and assign Divide and assign x /= 2 → x =
x/2
Floor divide and
//= Assignment Floor divide and assign x //= 2
assign
Modulus and Get remainder and
%= Assignment x %= 3
assign assign
Exponent and Raise to power and
**= Assignment x **= 2
assign assign
🟩 LOGICAL OPERATORS
Meaning /
Operator Type Why / When To Use Example
Name
Combine conditions – both True and False →
and Logical Logical AND
must be True False
or Logical Logical OR Combine conditions – only one True or False →
must be True True
not Logical Logical NOT Reverse the condition not True → False
🟨 IDENTITY OPERATORS
Meaning /
Operator Type Why / When To Use Example
Name
Object identity Check if two variables point to the
is Identity a is b
check same object in memory
Check if variables do not refer to
is not Identity Opposite of is a is not b
the same object
🟨 MEMBERSHIP OPERATORS
Meaning /
Operator Type Why / When To Use Example
Name
Check if Check if a value exists in a 'a' in 'apple' →
in Membership
value exists sequence (list, string, etc.) True
'x' not in
Value Check if a value does not
not in Membership 'banana' →
doesn't exist exist in a sequence
True
# ARITHMETIC
PRINT(X + Y)
# ASSIGNMENT
X += 2
# COMPARISON
PRINT(X > Y)
# LOGICAL
PRINT(X > Y AND Y > 0)
# IDENTITY
PRINT(X IS Y)
# MEMBERSHIP
PRINT('A' IN 'APPLE')
# BITWISE (ADVANCED)
PRINT(X & Y)