Python Operators (Multiple Choice Questions) MCQ – Python Interview objective questions| Python Quiz

11. What is the output of the following code

x = 6
y = 2
print(x ** y)
print(x // y)
  1. 66
    0
  2. 36
    0
  3. 66
    3
  4. 36
    3

Answer : D
Explanation: The Exponent (**) operator performs exponential (power) calculation. so here 6 ** 2 means 6*6 = 36 The // is the Floor Division operator so 6//2=3

12. What is the output of the following program :

i = 0
while i < 3:
       print i
       i++
       print i+1
  1. 0 2 1 3 2 4
  2. 0 1 2 3 4 5
  3. Error
  4. 1 0 2 4 3 5

Answer : C
Explanation: Python Programming language does not support ‘++’ operator.

13. Suppose the following statements are executed:

a = 100
b = 200

What is the value of the expression a and b?

  1. True
  2. 0
  3. False
  4. 200
  5. 100

Answer : D
Explanation: None

14. Operators with the same precedence are evaluated in which manner?

  1. Left to Right
  2. Right to Left
  3. Can’t say
  4. None of the mentioned

Answer : A
Explanation: None

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

  1. not
  2. &
  3. *
  4. +

Answer : C
Explanation: None

16. Given a function that does not return any value, what value is shown when executed at the shell?

  1. int
  2. bool
  3. void
  4. None

Answer : D
Explanation: Python explicitly defines the None object that is returned if no value is specified.

17. The function sqrt() from the math module computes the square root of a number. Will the highlighted line of code raise an exception?

x = -100
from math import sqrt
x > 0 and sqrt(x)
  1. Yes
  2. No
  3. void
  4. None

Answer : B
Explanation: In the highlighted line, x > 0 is False. The expression is already known to be falsy at that point. Due to short-circuit evaluation, sqrt(x) (which would raise an exception) is not evaluated.

18. Which one of the following has the same precedence level?

  1. Addition and Subtraction
  2. Multiplication, Division and Addition
  3. Multiplication, Division, Addition and Subtraction
  4. Addition and Multiplication

Answer : A
Explanation: “Addition and Subtraction” are at the same precedence level. Similarly, “Multiplication and Division” are at the same precedence level. However, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators.

19. What is the output of the following code


print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
  1. True True False True
  2. False True True True
  3. True True False True
  4. False True False True

Answer : B
Explanation: If we pass A zero value to the bool() constructor, it will treat it as false. Any non-zero value is true.

20. What is the output of the expression print(-18 // 4)

  1. -4
  2. -5
  3. 4
  4. 5

Answer : B
Explanation: In the case of the floor division operator(//), when the result is negative, the result is rounded down to the next smallest (big negative) integer.

Leave a Reply