Placement Prep

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.

By FACE Prep Team 6 min read
python operators python-operators arithmetic-operators bitwise-operators placement-prep

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:

CategoryOperators
Arithmetic+, -, *, /, //, %, **
Comparison==, !=, >, <, >=, <=
Logicaland, or, not
Assignment=, +=, -=, *=, /=, //=, %=, **=
Bitwise&, |, ^, ~, <<, >>
Identityis, is not
Membershipin, not in

Arithmetic Operators

Arithmetic operators perform mathematical calculations on numeric values.

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction5 - 32
*Multiplication5 * 315
/Division (float)5 / 31.6666...
//Floor division5 // 31
%Modulo (remainder)5 % 32
**Exponentiation5 ** 3125

Two points worth noting:

  • / always returns a float in Python 3, even when the result is a whole number (6 / 2 gives 3.0, not 3).
  • // discards the decimal and rounds down toward negative infinity, so -7 // 2 gives -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.

OperatorDescriptionExampleResult
==Equal to5 == 3False
!=Not equal to5 != 3True
>Greater than5 > 3True
<Less than5 < 3False
>=Greater than or equal to5 >= 5True
<=Less than or equal to5 <= 3False

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.

OperatorReturns True when…ExampleResult
andBoth operands are truthy(5 > 3) and (3 > 1)True
orAt least one operand is truthy(5 > 3) or (3 < 1)True
notOperand 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.

OperatorEquivalent toExampleValue of a after (if a was 5)
=Assigna = 55
+=a = a + na += 38
-=a = a - na -= 32
*=a = a * na *= 315
/=a = a / na /= 22.5
//=a = a // na //= 31
%=a = a % na %= 32
**=a = a ** na **= 3125

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.

OperatorDescriptionExampleResult
&Bitwise AND5 & 31
|Bitwise OR5 | 37
^Bitwise XOR5 ^ 36
~Bitwise NOT~5-6
<<Left shift5 << 110
>>Right shift5 >> 12

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: 101 becomes 1010 = 10
  • 5 >> 1: 101 becomes 10 = 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.

OperatorReturns True when…
isBoth variables reference the same object
is notVariables 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).

OperatorReturns True when…Example
inValue is found in the sequence'a' in 'apple'True
not inValue 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.

Build AI projects

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)
Free AI Roadmap PDF