Python Exponentiation Operator Right-Associativity
What is the output of: print(2 ** 3 ** 2)?
Quick Answer
The correct output is 512. This result follows directly from Python’s exponentiation operator right-associativity, which dictates that when multiple ** operators appear in a chain, the expression is evaluated from right to left. So `2 ** 3 ** 2` is parsed as `2 ** (3 ** 2)`, not `(2 ** 3) ** 2`; first `3 ** 2` yields 9, then `2 ** 9` gives 512. On the Certified Entry-Level Python Programmer PCEP exam, this concept tests your understanding of operator precedence and associativity—a common trap is assuming left-to-right evaluation, which would incorrectly produce 64. A reliable memory tip: think of exponentiation as building a tower from the top down, so you always compute the highest exponent first.
⚠ Common exam trap
It's easy for candidates to assume left-to-right associativity for all operators, forgetting that ** is right-associative, leading them to pick 64 instead of 512.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
512
In Python, the exponentiation operator ** is right-associative, meaning that `2 ** 3 ** 2` is evaluated as `2 ** (3 ** 2)`, not `(2 ** 3) ** 2`. First, `3 ** 2` equals 9, then `2 ** 9` equals 512. Thus, the correct output is 512.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
512
Why this is correct
The exponentiation operator ** is right-associative, so 3 ** 2 evaluates first to 9, then 2 ** 9 yields 512. Left-to-right evaluation would give 64, but Python's grammar groups the rightmost operation first, producing 512.
- ✗
12
Why it's wrong here
Exponentiation is right-associative, so 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2), giving 2 ** 9 = 512. The value 12 would require (2 ** 3) * 2 or similar, mixing multiplication with exponentiation. The option tempts by treating the operators as left-associative.
- ✗
64
Why it's wrong here
Exponentiation is right-associative, so 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2) = 2 ** 9 = 512, not 64. The value 64 equals (2 ** 3) ** 2, which assumes left-to-right grouping. The option tempts by applying the associativity of multiplication and addition.
- ✗
256
Why it's wrong here
Python's exponentiation operator ** is right-associative, so 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2) = 2 ** 9 = 512, not 256. The value 256 arises from wrongly applying left-to-right associativity, giving (2 ** 3) ** 2 = 8 ** 2. Left-associativity applies to operators like subtraction, not exponentiation.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output?
medium- A.Error
- B.9
- C.6
- ✓ D.8
Why D: The code `print(2 ** 3)` computes 2 raised to the power of 3, which equals 8. Exponentiation is performed right-to-left and has higher precedence than multiplication, but in this simple case, it directly yields 8. Therefore, option D is correct.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.