Test your understanding of Python operators with these beginner-friendly MCQs. Practice key concepts like arithmetic, comparison, logical, bitwise, and assignment operators with instant answers and explanations.
Topic: operators
print(7 / 2)
3.5
True division (/) always returns a float in Python 3.
print(5 == 5.0)
True
Python considers numeric values equal regardless of type (int vs float).
print(3 != '3')
True
Different types (int vs str) are not equal in Python.
x = 5
x **= 3
125
Exponentiation assignment: x = x ** 3 → 5^3 = 125.
x = 10
x %= 3
print(x)
1
Modulus assignment: x = x % 3 → remainder of 10/3 is 1.
print('ell' in 'hello')
True
Membership operator checks for substring presence.
print(3 not in [1, 2, 4])
True
3 is not present in the list, so 'not in' returns True.
x = 10
y = 5
x = x + y
y = x - y
x = x - y
print(x, y)
5 10
This code swaps the values of x and y without using a temporary variable.
x = 10
y = 5
print(x % y)
0
The modulus operator returns the remainder of 10 divided by 5, which is 0.
x = 5
y = 10
result = x > 3 or y < 5
print(result)
True
The expression evaluates to True because x > 3 is True (even though y < 5 is False).
x = 10; x //= 3
3
The floor division operator // returns the largest integer less than or equal to the division result.
num = 4
result = num in [1, 3, 4]
print(result)
True
The 'in' operator checks for membership and returns True since 4 is in the list.
10 // 3 * 2
6
Floor division (//) happens first (10//3=3), then multiplication (3*2=6).
print(10 <= 5 or 3 > 2)
True
The second condition (3 > 2) is True, making the entire OR expression True.
print(not (True and False))
True
Inner expression (True and False) evaluates to False, then NOT False becomes True.
print(5 is 5.0)
False
Different memory objects despite equal value (int vs float).
a = [1, 2]
b = a
print(a is b)
True
b references the same list object as a (same memory location).
print(10 << 2)
40
Left shift: 10 * 2^2 = 40 (binary 1010 shifted left becomes 101000).
print((2 + 3) * 4 ** 2)
80
Parentheses first (2+3=5), then exponent (4^2=16), then multiplication (5*16=80).
print(True + False + 10)
11
Boolean values are subclass of int (True=1, False=0), so 1 + 0 + 10 = 11.
print(10 < 9 < 8)
False
Chained comparison: equivalent to (10 < 9) and (9 < 8), both False.
2 ** 3 + 4 // 2 - 1
9
The expression evaluates as (8) + (2) - 1 = 9 due to operator precedence.
both A and C are correct
The 'and' operator requires both conditions to be True, while 'or' requires at least one to be True.
2 ** 3 ** 2
512
Exponentiation is right-associative: evaluates as 2 ** (3 ** 2) = 2^9 = 512.
print(False or not True and True)
False
Operator precedence: NOT first (not True=False), then AND (False and True=False), then OR (False or False=False).
print(5 & 3)
1
Bitwise AND: 0101 (5) & 0011 (3) = 0001 (1).
print(2 + 3 * 4 ** 2)
50
Order: exponentiation (4**2=16), then multiplication (3*16=48), then addition (2+48=50).