Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: In the expression print(2**3**2, (2**3)**2) what are the two values printed, in order?

  1. A. 64 512
  2. B. 512 64
  3. C. 512 512
  4. D. 8 64

Correct answer: B. 512 64

Exponentiation in Python is right-associative, so 2**3**2 means 2**(3**2) = 512. Evaluating left to right gives 64, the second printed value.

More Coding Interview Problems questions

Exams that ask this topic