ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(2**3**2, (2**3)**2, -2**2, (-2)**2, 2**-1**2)
  1. A. 512 64 -4 4 1.0
  2. B. 512 64 -4 4 0.5
  3. C. 2048 64 -4 4 0.5
  4. D. 512 64 -4 4 0.25

Correct answer: B. 512 64 -4 4 0.5

** is right-associative, so 2**3**2 is 2**9 = 512. Unary minus binds looser than **, so -2**2 is -4, and 2**-1**2 is 2**(-1) = 0.5.

More Python Programming questions

Exams that ask this topic