Latest Python Operators MCQs

1 min read

Operators in Python are special symbols and keywords used to manipulate data, perform mathematical computations, make boolean comparisons, and control execution logic. Beyond fundamental arithmetic (+, -, *, /, //, %, **), Python includes advanced operators like the assignment expression walrus operator (:=), matrix multiplication (@), dictionary union operators (| and |=), and bitwise operators (&, |, ^, ~, <<, >>). Understanding operator evaluation order, short-circuit behavior in logical operations (and, or), identity versus equality (is vs ==), and sequence repetition is essential for writing efficient Python code and passing modern technical assessments.

1. What is the result of the expression 10 // 3 in Python 3?

a) 3.3333333333333335
b) 3
c) 3.0
d) 4
Correct Answer: b) 3
Explanation:
The floor division operator (//) divides two numbers and rounds down to the nearest integer. Since both operands are integers, the result is an integer.

2. What is the output of -10 // 3 in Python?

a) -3
b) -3.33
c) -4
d) -3.0
Correct Answer: c) -4
Explanation:
Python performs floor division by rounding down toward negative infinity. -10 / 3 equals -3.333..., which floors down to -4.

3. Which Python operator has the highest precedence among the following?

a) + (Addition)
b) * (Multiplication)
c) ** (Exponentiation)
d) == (Equality)
Correct Answer: c) ** (Exponentiation)
Explanation:
Exponentiation (**) has a higher precedence than arithmetic multiplication/addition and comparison operators in Python.

4. What is the evaluated output of the expression 2 ** 3 ** 2?

a) 64
b) 512
c) 65536
d) 256
Correct Answer: b) 512
Explanation:
The exponentiation operator (**) groups right-to-left. Therefore, 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512.

5. What is the output of the expression 7 % -3 in Python?

a) 1
b) -1
c) 2
d) -2
Correct Answer: d) -2
Explanation:
In Python, the modulo operator result takes the sign of the divisor. Using the formula r = a - (b * (a // b)): 7 - (-3 * (7 // -3)) = 7 - (-3 * -3) = 7 - 9 = -2.

6. Which operator is used to test if two variables point to the same object in memory?

a) ==
b) is
c) in
d) equals
Correct Answer: b) is
Explanation:
The identity operator 'is' evaluates to True if both variables point to the exact same object memory location, whereas '==' compares values.

7. What is the result of [1, 2] == [1, 2] and [1, 2] is [1, 2]?

a) True and True
b) True and False
c) False and True
d) False and False
Correct Answer: b) True and False
Explanation:
The two list instances have identical values, so '==' returns True. However, lists are mutable so Python creates two separate object instances, making 'is' return False.

8. What will be the output of 'a' in {'a': 1, 'b': 2}?

a) True
b) False
c) 1
d) KeyError
Correct Answer: a) True
Explanation:
The membership operator 'in' checks for keys when used directly on a dictionary in Python.

9. What is the result of 1 in {1: 'a', 2: 'b'}.values()?

a) True
b) False
c) TypeError
d) KeyError
Correct Answer: b) False
Explanation:
The values inside the dictionary are strings ('a', 'b'), not the integer 1. Therefore, searching for 1 in dict.values() returns False.

10. What is the output of 5 & 3 in Python?

a) 1
b) 7
c) 5
d) 3
Correct Answer: a) 1
Explanation:
Bitwise AND (&) compares binary representations. 5 is 0101 in binary and 3 is 0011. Performing bitwise AND gives 0001, which is 1.

11. What is the result of 5 | 3 in Python?

a) 1
b) 7
c) 8
d) 15
Correct Answer: b) 7
Explanation:
Bitwise OR (|) computes 0101 | 0011 = 0111 in binary, which equals 7 in decimal.

12. What is the output of 5 ^ 3 in Python?

a) 1
b) 7
c) 6
d) 2
Correct Answer: c) 6
Explanation:
Bitwise XOR (^) returns 1 where bits differ. 0101 ^ 0011 = 0110 in binary, which evaluates to 6 in decimal.

13. What does the bitwise NOT operator ~5 evaluate to in Python?

a) -5
b) -6
c) -4
d) 5
Correct Answer: b) -6
Explanation:
The bitwise NOT operator (~) returns ~x = -(x + 1). Hence, ~5 yields -(5 + 1) = -6.

14. What is the value of 5 >) shifts bits to the right, equivalent to floor division by 2**n. 20 // (2**2) = 20 // 4 = 5.

Correct Answer:

15. What does the assignment expression operator := (walrus operator) do?

a) Compares equality and assigns values.
b) Assigns values to variables as part of a larger expression.
c) Creates immutable constants.
d) Executes dynamic typed variables.
Correct Answer: b) Assigns values to variables as part of a larger expression.
Explanation:
Introduced in Python 3.8, the walrus operator (:=) enables value assignment directly inside expressions (e.g., inside while loops or conditional statements).

16. What is the output of 'Hello' or 'World' in Python?

a) True
b) 'Hello'
c) 'World'
d) False
Correct Answer: b) 'Hello'
Explanation:
The logical 'or' operator evaluates operands from left to right and returns the first truthy value encountered without evaluating the remaining operands.

17. What is the output of '' and 'Python'?

a) ''
b) 'Python'
c) False
d) True
Correct Answer: a) ''
Explanation:
The logical 'and' operator returns the first falsy value it encounters. Since the empty string '' is falsy, it is returned directly.

18. What does 0 or False or [] or 'Python' evaluate to?

a) 0
b) False
c) []
d) 'Python'
Correct Answer: d) 'Python'
Explanation:
The 'or' operator checks operands until it finds a truthy value. Since 0, False, and [] are all falsy, it proceeds to and returns 'Python'.

19. What is the evaluated output of True + True * 3?

a) 6
b) 4
c) 3
d) TypeError
Correct Answer: b) 4
Explanation:
In Python, bool is a subclass of int where True equals 1. With precedence rules, True * 3 is 1 * 3 = 3, and True + 3 becomes 1 + 3 = 4.

20. What is the result of 10 > 5 > 2 in Python?

a) True
b) False
c) 10
d) SyntaxError
Correct Answer: a) True
Explanation:
Python supports chained comparisons. 10 > 5 > 2 is evaluated as (10 > 5) and (5 > 2), which is True and True = True.

21. What does 1 == 1.0 evaluate to?

a) True
b) False
c) TypeError
d) None
Correct Answer: a) True
Explanation:
Python performs implicit type promotion when comparing integers and floats, so the integer 1 and float 1.0 are considered equal in value.

22. What is the result of 1 is 1.0?

a) True
b) False
c) TypeError
d) SyntaxError
Correct Answer: b) False
Explanation:
The 'is' operator checks for object identity (memory location and type). Int and float objects are distinct types stored separately in memory.

23. Which of the following method corresponds to the binary + operator overload in Python?

a) __plus__
b) __add__
c) __sum__
d) __concat__
Correct Answer: b) __add__
Explanation:
The special magic method __add__(self, other) is used to define or override the behavior of the addition operator (+).

24. Which dunder method handles reverse addition, such as when the left operand does not support +?

a) __revadd__
b) __radd__
c) __iadd__
d) __backadd__
Correct Answer: b) __radd__
Explanation:
The __radd__ method is called when the left operand does not implement __add__ or returns NotImplemented.

25. Which dunder method is called when using the in-place addition operator +=?

a) __add__
b) __iadd__
c) __inplace_add__
d) __plus_equal__
Correct Answer: b) __iadd__
Explanation:
The __iadd__ method implements in-place addition assignment (+=).

26. What is the value of x after executing x = 5; x += 3 * 2?

a) 16
b) 11
c) 13
d) 10
Correct Answer: b) 11
Explanation:
The right side of the assignment (3 * 2 = 6) is evaluated first. Then x += 6 evaluates to 5 + 6 = 11.

27. What is the output of 'Py' + 'thon'?

a) 'Py thon'
b) 'Python'
c) TypeError
d) ['Py', 'thon']
Correct Answer: b) 'Python'
Explanation:
When applied to strings, the + operator performs sequence concatenation.

28. What is the output of [1, 2] * 3?

a) [3, 6]
b) [1, 2, 1, 2, 1, 2]
c) [[1, 2], [1, 2], [1, 2]]
d) TypeError
Correct Answer: b) [1, 2, 1, 2, 1, 2]
Explanation:
When a list is multiplied by an integer n, the list is repeated n times into a single flat list.

29. What is the output of not 0 in Python?

a) 0
b) 1
c) True
d) False
Correct Answer: c) True
Explanation:
The integer 0 is evaluated as falsy in a boolean context. Negating it with 'not' yields True.

30. What is the output of not 'False'?

a) True
b) False
c) None
d) TypeError
Correct Answer: b) False
Explanation:
'False' is a non-empty string, making it truthy. Negating a truthy value returns False.

31. What is the output of 3.0 // 2?

a) 1
b) 1.0
c) 1.5
d) 2.0
Correct Answer: b) 1.0
Explanation:
If either operand in floor division is a float, the result is returned as a float rounded down (1.0).

32. What is the output of 10 / 2 in Python 3?

a) 5
b) 5.0
c) 5.00
d) TypeMismatch
Correct Answer: b) 5.0
Explanation:
The single slash (/) operator in Python 3 always performs true division and returns a floating-point number.

33. Which of the following is NOT a valid operator in Python?

a) //
b) ::
c) :=
d) **
Correct Answer: b) ::
Explanation:
The '::' symbol is used in slicing notation, but it is not classified as an independent stand-alone Python operator.

34. What will 3 < 4 == True evaluate to?

a) True
b) False
c) TypeError
d) SyntaxError
Correct Answer: b) False
Explanation:
This expression is chained as (3 < 4) and (4 == True). While 3 < 4 is True, 4 == True evaluates to False, making the overall result False.

35. What is the value of ~(-6) in Python?

a) 5
b) 6
c) -5
d) -7
Correct Answer: a) 5
Explanation:
The formula for ~x is -(x + 1). Applying this to -6 gives -(-6 + 1) = -(-5) = 5.

36. What is the evaluation of bool([]) or bool('')?

a) True
b) False
c) None
d) []
Correct Answer: b) False
Explanation:
Both empty list [] and empty string '' convert to False. False or False returns False.

37. Which operator corresponds to the __eq__ dunder method?

a) =
b) ==
c) is
d) eq
Correct Answer: b) ==
Explanation:
The equality comparison operator (==) invokes the object's __eq__ method.

38. Which method is invoked by the bitwise left shift ( 5) and (5 is True). 5 is True evaluates to False, so the combined result is False.

Correct Answer:

39. What is the result of (10 > 5) is True?

a) True
b) False
c) SyntaxError
d) TypeError
Correct Answer: a) True
Explanation:
Parentheses force (10 > 5) to evaluate first to True. Then True is True evaluates to True.

40. What dunder method overloads the floor division // operator?

a) __floordiv__
b) __fdiv__
c) __intdiv__
d) __floor__
Correct Answer: a) __floordiv__
Explanation:
The __floordiv__(self, other) method handles the overload for floor division.

41. Which dunder method corresponds to the modulo operator %?

a) __mod__
b) __modulo__
c) __rem__
d) __remainder__
Correct Answer: a) __mod__
Explanation:
The __mod__ method defines the behavior of the % operator.

42. What is the result of divmod(10, 3)?

a) (3, 1)
b) [3, 1]
c) 3
d) 1
Correct Answer: a) (3, 1)
Explanation:
The divmod(a, b) function returns a tuple (a // b, a % b).

43. Which dunder method handles divmod(a, b)?

a) __divmod__
b) __dm__
c) __div_mod__
d) __floor_mod__
Correct Answer: a) __divmod__
Explanation:
The __divmod__ dunder method implements the built-in divmod() behavior for custom classes.

44. What is the result of 10 != 10.0?

a) True
b) False
c) TypeError
d) None
Correct Answer: b) False
Explanation:
10 and 10.0 are equal in value, so the inequality operator (!=) returns False.

45. What is the output of 'a' < 'b'?

a) True
b) False
c) TypeError
d) 0
Correct Answer: a) True
Explanation:
Strings are compared lexicographically using their Unicode scalar values (ord('a') = 97 < ord('b') = 98).

46. What does 'abc' < 'ab' return?

a) True
b) False
c) TypeError
d) Equal
Correct Answer: b) False
Explanation:
In lexicographical string comparison, longer strings with matching prefixes are considered greater than shorter strings.

47. What is the result of [1, 2, 3] < [1, 2, 4]?

a) True
b) False
c) TypeError
d) None
Correct Answer: a) True
Explanation:
Python compares sequences element-by-element in order. Since 3 < 4 at index 2, the result is True.

48. What happens when you execute [1, 'a'] < [1, 2]?

a) True
b) False
c) Raises TypeError
d) Compares string length
Correct Answer: c) Raises TypeError
Explanation:
Index 1 compares 'a' with 2. In Python 3, unorderable types (str vs int) throw a TypeError during comparison.

49. What is the result of bool(0) or bool(None)?

a) True
b) False
c) None
d) 0
Correct Answer: b) False
Explanation:
Both bool(0) and bool(None) evaluate to False. False or False equals False.

50. What is the evaluated result of 0.1 + 0.2 == 0.3 in Python?

a) True
b) False
c) TypeError
d) Approximation
Correct Answer: b) False
Explanation:
Due to floating-point representation limitations in IEEE 754 standard, 0.1 + 0.2 equals 0.30000000000000004, which is not equal to 0.3.

51. Which module function is recommended to reliably check floating point equality?

a) math.isclose()
b) math.equals()
c) float.same()
d) sys.check_float()
Correct Answer: a) math.isclose()
Explanation:
math.isclose(a, b) handles tiny precision rounding errors when comparing floating point numbers.

52. What is the value of 16 >> 1?

a) 32
b) 8
c) 4
d) 16
Correct Answer: b) 8
Explanation:
Right shifting by 1 bit effectively divides an integer by 2 (16 // 2 = 8).

53. What is the value of 1 2 and 3 < 1)?

a) True
b) False
c) None
d) TypeError
Correct Answer: a) True
Explanation:
5 > 2 is True and 3 < 1 is False, so inner expression is False. 'not False' evaluates to True.

54. What does x is not Y check?

a) Checks if values are unequal
b) Checks if object references point to different memory identities
c) Checks if types are different
d) Checks if values are equal but types differ
Correct Answer: b) Checks if object references point to different memory identities
Explanation:
'is not' tests identity negation (id(x) != id(y)).

55. What is the output of 'a' in 'apple'?

a) True
b) False
c) 1
d) Index Error
Correct Answer: a) True
Explanation:
The 'in' membership operator checks if the left string exists as a substring of the right string.

56. What is the output of 5.5 // 2?

a) 2
b) 2.0
c) 2.75
d) 3.0
Correct Answer: b) 2.0
Explanation:
5.5 // 2 evaluates floor division (2.75 floored to 2.0) and retains float type due to operand float type.

57. What is the value of -5.5 // 2?

a) -2.0
b) -3.0
c) -2.75
d) -3
Correct Answer: b) -3.0
Explanation:
-5.5 / 2 = -2.75. Flooring toward negative infinity rounds down to -3.0.

58. What operator is used to calculate remainder in Python?

a) /
b) //
c) %
d) #
Correct Answer: c) %
Explanation:
The modulus operator % calculates the remainder of division.

59. What is the result of 14 % 5?

a) 2.8
b) 4
c) 2
d) 1
Correct Answer: b) 4
Explanation:
14 divided by 5 equals 2 with a remainder of 4.

60. Which of the following statement is TRUE regarding Python comparison operators?

a) They return integer 1 or 0
b) They return boolean True or False
c) They raise errors when comparing different numbers
d) They can only compare two variables at a time
Correct Answer: b) They return boolean True or False
Explanation:
Comparison operators in Python evaluate expressions and return boolean True or False.

61. Which operator performs in-place bitwise XOR assignment?

a) ^=
b) x=
c) &=
d) ~=
Correct Answer: a) ^=
Explanation:
The ^= augmented assignment operator performs bitwise XOR and reassigns the result.

62. What is the output of min([1, 2, 3]) < max([1, 2, 3])?

a) True
b) False
c) 1
d) 3
Correct Answer: a) True
Explanation:
min() is 1 and max() is 3. The comparison 1 < 3 evaluates to True.

63. Which of the following will result in a SyntaxError?

a) x = 5++
b) x = ++5
c) x = +5
d) x = -(-5)
Correct Answer: a) x = 5++
Explanation:
Python does not support post-increment (5++) or pre-increment (++var) operators found in C/C++. 5++ generates a SyntaxError.

64. What does x = ++5 evaluate to in Python?

a) 6
b) 5
c) SyntaxError
d) 7
Correct Answer: b) 5
Explanation:
Python parses ++5 as two unary positive operators: +(+5), which simply evaluates to 5.

65. What is the value of x after x = --5?

a) 4
b) 5
c) -5
d) SyntaxError
Correct Answer: b) 5
Explanation:
Python interprets --5 as -(-5), applying unary minus twice, which evaluates to positive 5.

66. Which dunder method corresponds to unary minus (-x)?

a) __sub__
b) __neg__
c) __minus__
d) __negative__
Correct Answer: b) __neg__
Explanation:
The __neg__ special method defines behavior for the unary negation operator.

67. Which dunder method corresponds to unary plus (+x)?

a) __add__
b) __pos__
c) __plus__
d) __positive__
Correct Answer: b) __pos__
Explanation:
The __pos__ special method overloads unary positive operator (+x).

68. Which dunder method corresponds to abs(x)?

a) __absolute__
b) __abs__
c) __val__
d) __posval__
Correct Answer: b) __abs__
Explanation:
The __abs__ special method defines behavior for the built-in abs() function.

69. Which of the following expressions uses ternary operator style in Python?

a) x ? a : b
b) a if x else b
c) if x then a else b
d) switch(x) { case a: b }
Correct Answer: b) a if x else b
Explanation:
Python supports conditional expressions (ternary operator) using the syntax: 'value_if_true if condition else value_if_false'.

70. What does 'pass' if True else 'fail' evaluate to?

a) 'pass'
b) 'fail'
c) True
d) SyntaxError
Correct Answer: a) 'pass'
Explanation:
Since the condition True holds, the conditional expression evaluates to the left value 'pass'.

71. What is the output of 10 > 2 and 2 < 1 or 10 == 10?

a) True
b) False
c) None
d) 10
Correct Answer: a) True
Explanation:
10 > 2 and 2 < 1 evaluates to False. Then False or (10 == 10) evaluates to True.

72. What is the output of not 10 < 20?

a) True
b) False
c) 10
d) 20
Correct Answer: b) False
Explanation:
10 < 20 is True. Applying 'not' to True produces False.

73. What is the value of bool(10)

a) True
b) False
c) 10
d) TypeError
Correct Answer: a) True
Explanation:
Any non-zero numerical value evaluates to True in Python.

74. What is the outcome of 0.5.is_integer()?

a) True
b) False
c) AttributeError
d) TypeError
Correct Answer: b) False
Explanation:
float.is_integer() checks if the float instance represents an integer value. 0.5 has fractional components so it returns False.

75. What is the output of 2.0.is_integer()?

a) True
b) False
c) SyntaxError
d) ValueError
Correct Answer: a) True
Explanation:
2.0 has zero fractional value, so float.is_integer() returns True.

76. Which of the following operators cannot be overloaded in Python?

a) is
b) +
c) ==
d) []
Correct Answer: a) is
Explanation:
The identity operator 'is' and logical operators ('and', 'or', 'not') cannot be overridden by custom magic methods.
← Previous: Latest Python Loops MCQs
Next →: Python Arrays MCQs
NewPython Functions MCQs

Python Functions MCQs

Functions in Python are reusable blocks of code designed to perform a specific task, promoting code modularity, readability, and DRY…

By MCQs Generator
Newpython variables & datatypes MCQs

Python Variables & Data Types MCQs

Variables in Python act as dynamic references reserved in memory to store objects, operating without explicit data type declarations due…

By MCQs Generator
NewPython Arrays MCQs

Python Arrays MCQs

Unlike many other programming languages, Python does not have a built-in static array data structure in its core syntax, instead…

By MCQs Generator