Python Operators

5 min read ·

Operators in Python are used to perform operations on variables and values. They are the backbone of logic, calculations, comparisons, and decision-making in Python programs.
This topic covers Python operators from basics to advanced, including tricky and interview-level concepts.

What Are Operators?

Operators are special symbols that perform operations on operands (values or variables).
Here:
  • + → operator
  • x and y → operands

Types of Python Operators

Python supports the following types of operators:
  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical Operators
  5. Identity Operators
  6. Membership Operators
  7. Bitwise Operators

Arithmetic Operators

Used to perform mathematical operations.
OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulus
**Exponentiation
//Floor Division

Assignment Operators

Used to assign values to variables.
OperatorExampleMeaning
=x = 5Assign
+=x += 3x = x + 3
-=x -= 2x = x - 2
*=x *= 2x = x * 2
/=x /= 2x = x / 2

Comparison Operators

Used to compare values and return Boolean results.
OperatorDescription
==Equal
!=Not equal
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

Logical Operators

Used to combine Boolean expressions.
OperatorMeaning
andTrue if both are true
orTrue if at least one is true
notReverses result

Identity Operators (Tricky)

Used to compare memory locations, not values.
OperatorMeaning
isSame object
is notNot same object

Membership Operators

Used to test whether a value exists in a sequence.
OperatorMeaning
inValue exists
not inValue does not exist

Bitwise Operators (Advanced)

Operate on binary values.
OperatorName
&AND
``OR
^XOR
~NOT
<<Left Shift
>>Right Shift

Operator Precedence (Very Important)

Python follows a specific order while evaluating expressions.
Key Rule

Parentheses () always have the highest priority.


Tricky Operator Examples (Interview Level)


Common Operator Mistakes

Using is instead of ==

Unreliable ❌

Correct Way


Practice (Hard)

  • Predict output of chained comparisons
  • Use bitwise operators on numbers
  • Find difference between is and ==
  • Write an expression using and, or, and not
This topic is core Python logic and appears everywhere—from basics to interviews.
Learn Python Python Operators | Python Course