Courseiva
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

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

    2**(3**2) = 2**9 = 512.

  • 12

    Why it's wrong here

    Incorrect.

  • 64

    Why it's wrong here

    That would be (2**3)**2 = 64, but associativity is right.

  • 256

    Why it's wrong here

    Incorrect.

About these practice questions

One of 498 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 →

How Courseiva writes practice questions · Editorial policy

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.