Types of Operators in Python: All 7 Types with Examples
Python has 7 operator types: arithmetic, comparison, logical, bitwise, assignment, identity, and membership. Learn each with code examples and placement tips.
Python has seven operator types: arithmetic, comparison, logical, assignment, bitwise, identity, and membership, each with a distinct role in writing expressions and controlling flow.
Knowing how each type works, and where it differs from similar-looking operators, is the baseline for reading Python correctly. This article covers all seven with tables, code examples, and the subtleties worth knowing before a placement assessment.
What Python Operators Are
An operator is a symbol that performs a specific operation on one or more operands (the values or variables it acts on). Together, they form an expression.
In a + b, for example, a and b are the operands and + is the operator.
Python organises its operators into seven categories:
| Category | Operators |
|---|---|
| Arithmetic | +, -, *, /, //, %, ** |
| Comparison | ==, !=, >, <, >=, <= |
| Logical | and, or, not |
| Assignment | =, +=, -=, *=, /=, //=, %=, **= |
| Bitwise | &, |, ^, ~, <<, >> |
| Identity | is, is not |
| Membership | in, not in |
Arithmetic Operators
Arithmetic operators perform mathematical calculations on numeric values.
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 3 | 2 |
* | Multiplication | 5 * 3 | 15 |
/ | Division (float) | 5 / 3 | 1.6666... |
// | Floor division | 5 // 3 | 1 |
% | Modulo (remainder) | 5 % 3 | 2 |
** | Exponentiation | 5 ** 3 | 125 |
Two points worth noting:
/always returns a float in Python 3, even when the result is a whole number (6 / 2gives3.0, not3).//discards the decimal and rounds down toward negative infinity, so-7 // 2gives-4, not-3.
a = 5
b = 3
print(a + b) # 8
print(a - b) # 2
print(a * b) # 15
print(a / b) # 1.6666666666666667
print(a // b) # 1
print(a % b) # 2
print(a ** b) # 125
These are the building blocks of programs like a simple calculator in Python.
Comparison Operators
Comparison operators compare two values and always return a boolean (True or False). Per the Python language reference, these are also called relational operators.
| Operator | Description | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 3 | False |
!= | Not equal to | 5 != 3 | True |
> | Greater than | 5 > 3 | True |
< | Less than | 5 < 3 | False |
>= | Greater than or equal to | 5 >= 5 | True |
<= | Less than or equal to | 5 <= 3 | False |
Comparison operators are central to conditional branching and programs like finding the greatest of three numbers.
Logical Operators
Logical operators combine boolean expressions. Python has three.
| Operator | Returns True when… | Example | Result |
|---|---|---|---|
and | Both operands are truthy | (5 > 3) and (3 > 1) | True |
or | At least one operand is truthy | (5 > 3) or (3 < 1) | True |
not | Operand is falsy (negates) | not (5 > 3) | False |
Short-circuit evaluation
and stops evaluating as soon as it encounters a falsy operand and returns that operand. or stops at the first truthy operand and returns it. This means the second operand is never evaluated when the first one decides the outcome.
x = 0
result = x and (10 / x) # Returns 0 — the division never runs
not on integers
not coerces its operand to bool before negating: not 0 is True (0 is falsy), and not 5 is False (5 is truthy). This is distinct from the bitwise ~ operator, which flips each bit: ~5 gives -6, not False. The two operators are not interchangeable.
Assignment Operators
Assignment operators assign a value to a variable. The compound forms combine an arithmetic operation with assignment in a single step.
| Operator | Equivalent to | Example | Value of a after (if a was 5) |
|---|---|---|---|
= | Assign | a = 5 | 5 |
+= | a = a + n | a += 3 | 8 |
-= | a = a - n | a -= 3 | 2 |
*= | a = a * n | a *= 3 | 15 |
/= | a = a / n | a /= 2 | 2.5 |
//= | a = a // n | a //= 3 | 1 |
%= | a = a % n | a %= 3 | 2 |
**= | a = a ** n | a **= 3 | 125 |
Bitwise Operators
Bitwise operators work on the binary representation of integers, applying the operation to each pair of corresponding bits. Per the Python documentation on integer bitwise operations, all six standard bitwise operators are supported.
| Operator | Description | Example | Result |
|---|---|---|---|
& | Bitwise AND | 5 & 3 | 1 |
| | Bitwise OR | 5 | 3 | 7 |
^ | Bitwise XOR | 5 ^ 3 | 6 |
~ | Bitwise NOT | ~5 | -6 |
<< | Left shift | 5 << 1 | 10 |
>> | Right shift | 5 >> 1 | 2 |
Worked example: 5 & 3
- 5 in binary:
101 - 3 in binary:
011 - AND of each bit:
001=1
Left and right shift
Left shift (<<) is equivalent to multiplying by a power of 2 for each position shifted. Right shift (>>) is equivalent to integer division by a power of 2.
5 << 1:101becomes1010=105 >> 1:101becomes10=2
Identity and Membership Operators
Identity Operators
Identity operators check whether two variables point to the same object in memory, not whether their values are equal.
| Operator | Returns True when… |
|---|---|
is | Both variables reference the same object |
is not | Variables reference different objects |
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a is c) # True — c and a point to the same list object
print(a is b) # False — b is a different object with the same values
print(a == b) # True — values are equal
print(a is not b) # True
The is vs == distinction is worth fixing in memory. Two lists can be == (same values) but fail is (different objects). Placement assessments use exactly this gap.
Membership Operators
Membership operators test whether a value is present in a sequence (list, tuple, string, set, or dictionary).
| Operator | Returns True when… | Example |
|---|---|---|
in | Value is found in the sequence | 'a' in 'apple' → True |
not in | Value is not found in the sequence | 'z' not in 'apple' → True |
These appear in programs like checking whether a character is uppercase, lowercase, a digit, or special, where in against a string keeps the condition concise.
Operators in Practice
The seven types together cover the main operations in Python: calculations, comparisons, condition combining, container lookups, object checks, and bit manipulation.
When multiple operators appear in the same expression, Python evaluates them in a defined order. For the complete precedence rules and how associativity resolves ties between operators of equal precedence, see the companion article on Python operator precedence and associativity.
The is versus == distinction and the short-circuit behaviour of and and or are the operator subtleties that placement screening rounds probe directly. Running your own test cases, rather than reading through examples, is how these distinctions stick. TinkerLLM gives you a live Python sandbox at ₹299 to work through these edge cases before test day.
Primary sources
Frequently asked questions
What are the 7 types of operators in Python?
Arithmetic, comparison (relational), logical, bitwise, assignment, identity, and membership operators.
What is the difference between `is` and `==` in Python?
`is` returns True only when both variables reference the same object in memory. `==` checks whether the values are equal. Two lists can be equal in value but still fail the `is` test.
What does the `//` operator do in Python?
Floor division: divides two numbers and returns the largest integer not greater than the result. `7 // 2` gives 3 and `7 // -2` gives -4 (rounds toward negative infinity, not toward zero).
What is the difference between `and` and `&` in Python?
`and` is a logical operator that short-circuits and returns one of its operands (not necessarily True or False). `&` is a bitwise operator that computes AND on each corresponding bit of two integers.
Does `not` work differently on integers?
Yes. `not x` coerces x to bool first: `not 0` is True (0 is falsy), `not 5` is False (5 is truthy). For bitwise NOT on integers, use `~`: `~5` gives -6.
Which Python operators appear in placement tests?
Comparison, logical, and identity operators appear in most Python screening rounds. Bitwise operators feature in TCS NQT technical sections. The `is` vs `==` distinction is a frequent trap question.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)