Python Operators MCQ

Operators are fundamental building blocks in any programming language. They perform operations on variables and values. Dive deep into Python’s operators with these 15 Multiple Choice Questions.

1. Which of the following is an arithmetic operator in Python?

a) &&
b) !=
c) //
d) ::

Answer:

c) //

Explanation:

// is the floor division operator in Python. It returns the quotient of the division, rounded down to the nearest whole number.

2. What will be the result of 9 % 4?

a) 1
b) 2
c) 3
d) 4

Answer:

c) 3

Explanation:

% is the modulus operator, which returns the remainder of the division. 9 % 4 returns 3.

3. Which of the following operators has the highest precedence?

a) +
b) *
c) **
d) –

Answer:

c) **

Explanation:

** is the exponentiation operator, and it has the highest precedence among the options listed.

4. What does the == operator do?

a) Assigns value
b) Compares value and returns true or false
c) Checks memory location
d) None of the above

Answer:

b) Compares value and returns true or false

Explanation:

== is a comparison operator that checks for equality of values and returns True if they are equal, otherwise False.

5. What is the output of 2 ** 3?

a) 5
b) 6
c) 8
d) 11

Answer:

c) 8

Explanation:

** is the exponentiation operator. 2 ** 3 calculates 2 raised to the power of 3, which is 8.

6. Which operator is used for bitwise XOR in Python?

a) &
b) |
c) !
d) ^

Answer:

d) ^

Explanation:

The ^ operator in Python is used for bitwise XOR operations.

7. Which of the following is a membership operator in Python?

a) in
b) is
c) ==
d) !=

Answer:

a) in

Explanation:

in is a membership operator in Python used to check if a value is present in a sequence (like a list or tuple).

8. What does the is operator do in Python?

a) Checks value equality
b) Assigns value
c) Checks memory location
d) All of the above

Answer:

c) Checks memory location

Explanation:

The is operator checks if both the operands refer to the same object in memory (i.e., they have the same memory location).

9. If a = 3 and b = 3, what will be the result of (a is b)?

a) True
b) False
c) Error
d) None

Answer:

a) True

Explanation:

In Python, small integers (like 3) are cached. Both a and b refer to the same memory location, so (a is b) returns True.

10. Which operator is used for floor division?

a) /
b) *
c) //
d) %

Answer:

c) //

Explanation:

// is the floor division operator that returns the quotient of the division, rounded down to the nearest whole number.

11. Which operator is used to check if an object is NOT part of a sequence?

a) in
b) not in
c) is not
d) !=

Answer:

b) not in

Explanation:

not in is a membership operator used to check if an object is NOT part of a sequence.

12. What is the result of 10 & 7?

a) 2
b) 3
c) 6
d) 7

Answer:

a) 2

Explanation:

The & operator performs a bitwise AND operation. 10 in binary is 1010 and 7 is 0111. The result of bitwise AND operation is 0010, which is 2 in decimal.

13. Which operator has the lowest precedence?

a) or
b) and
c) not
d) ==

Answer:

a) or

Explanation:

Among the given options, the logical or operator has the lowest precedence.

14. What is the result of True or False and False?

a) True
b) False
c) Error
d) None

Answer:

a) True

Explanation:

The and operator has higher precedence than or. Therefore, False and False is evaluated first and results in False. Then, True or False results in True.

15. What does the += operator do?

a) Multiplies and assigns
b) Divides and assigns
c) Adds and assigns
d) Subtracts and assigns

Answer:

c) Adds and assigns

Explanation:

The += operator adds the right operand to the left operand and assigns the result to the left operand. It’s shorthand for a = a + b.


By taking this quiz, you’ve reinforced your understanding of operators in Python. Continuously challenging yourself helps in better retention and understanding. Keep it up and happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top