Python Operators MCQ Questions and Answers

Operators in Python are special symbols that carry out arithmetic or logical computation. The value that the operator operates on is called the operand. Here we present 20 multiple-choice questions to test your knowledge of Python operators, including arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. Each MCQ has the correct answer with an explanation.

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

a) 3
b) 3.33
c) 3.0
d) 3.3333333333333335

Answer:

d) 3.3333333333333335

Explanation:

The / operator in Python performs floating-point division and returns a float.

2. How do you raise 4 to the power of 3 in Python?

a) 4 ^ 3
b) 4 ** 3
c) 4 * 3
d) pow(4, 3)

Answer:

b) 4 ** 3

Explanation:

The ** operator is used for exponentiation in Python.

3. What is the purpose of the %= operator in Python?

a) Modulus and assign
b) Multiply and assign
c) Modulus and compare
d) None of the above

Answer:

a) Modulus and assign

Explanation:

The %= operator takes the modulus using two operands and assigns the result to the left operand.

4. What does the comparison operator != check in Python?

a) Equality
b) Less than
c) Greater than
d) Not equal

Answer:

d) Not equal

Explanation:

The != operator checks whether two values are not equal.

5. What is the result of the logical operation "True or False" in Python?

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

Answer:

a) True

Explanation:

The logical 'or' operator returns True if any of the operands is True.

6. What does the 'is' operator do in Python?

a) Checks if two variables have the same value
b) Checks if two variables are the same object
c) Compares the memory addresses of two variables
d) b and c

Answer:

d) b and c

Explanation:

The 'is' operator checks if two variables point to the same object in memory.

7. How do you check if 'a' is in the list [1, 2, 'a', 'b'] using Python?

a) 'a' in [1, 2, 'a', 'b']
b) 'a' is in [1, 2, 'a', 'b']
c) [1, 2, 'a', 'b'].contains('a')
d) [1, 2, 'a', 'b'].has('a')

Answer:

a) 'a' in [1, 2, 'a', 'b']

Explanation:

The 'in' operator is used to check if a value exists within an iterable.

8. What does the bitwise operator & do in Python?

a) Addition
b) Bitwise AND
c) Bitwise OR
d) Assignment

Answer:

b) Bitwise AND

Explanation:

The & operator performs a bitwise AND operation.

9. What is the result of 5 + 3 * 2 in Python?

a) 16
b) 11
c) 13
d) 10

Answer:

b) 11

Explanation:

Python follows mathematical precedence, so multiplication is performed before addition.

10. Which operator is used for floor division in Python?

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

Answer:

b) //

Explanation:

The // operator performs floor division.

11. How do you increment the value of a variable 'x' by 1 in Python?

a) x++
b) x += 1
c) x =+ 1
d) ++x

Answer:

b) x += 1

Explanation:

Python uses += for incrementing a value. The ++ operator is not available in Python.

12. What will be the result of '12 > 9 > 7' in Python?

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

Answer:

a) True

Explanation:

Python allows chain comparison operations, which in this case checks if 12 is greater than 9 and if 9 is greater than 7.

13. Which statement correctly checks if two variables a and b are equal in Python?

a) if a = b:
b) if a == b:
c) if a === b:
d) if a equals b:

Answer:

b) if a == b:

Explanation:

The double equals (==) operator is used for equality comparison in Python.

14. What does 'not True' evaluate to in Python?

a) 0
b) False
c) ''
d) None

Answer:

b) False

Explanation:

The 'not' operator inverts the Boolean value, so 'not True' evaluates to False.

15. Which operator can be used to determine if two variables refer to the same object?

a) ==
b) ===
c) is
d) equals

Answer:

c) is

Explanation:

The 'is' operator checks identity, not equality, and determines if two variables refer to the same object.

16. What is the output of the expression ['apple', 'banana'] in ['apple', 'banana', 'cherry']?

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

Answer:

b) False

Explanation:

The 'in' operator checks for the presence of a single element in an iterable, not a sublist.

17. What is the result of the bitwise shift right operation 4 >> 1 in Python?

a) 2
b) 8
c) 1
d) 16

Answer:

a) 2

Explanation:

The >> operator is the bitwise shift right operator, shifting the bits of 4 to the right by 1, which results in 2.

18. What does 'a *= 2' do if a = 5?

a) Multiplies a by 2 and assigns the result to a
b) Raises a to the power of 2
c) Doubles the type of a
d) None of the above

Answer:

a) Multiplies a by 2 and assigns the result to a

Explanation:

The *= operator is a compound assignment operator that multiplies the variable by a value and assigns the result to the variable.

19. What is the result of the expression '10 == "10"' in Python?

a) True
b) False
c) SyntaxError
d) TypeError

Answer:

b) False

Explanation:

Python does not automatically convert between types for comparison, so an integer compared to a string will result in False.

20. What does the expression 2 | 4 evaluate to in Python?

a) 6
b) 8
c) 0
d) 2

Answer:

a) 6

Explanation:

The | operator is a bitwise OR. 2 in binary is 010, and 4 is 100. The bitwise OR results in 110, which is 6 in decimal.

Leave a Comment

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

Scroll to Top