Courseiva

PCAP Object-Oriented Programming Practice Question

A developer writes a class `Circle` with `def __init__(self, radius): self.radius = radius` and wants printing a `Circle` instance to produce a readable description such as `Circle(5)`. Which method should be implemented, and why over the alternative?

⚠ Common exam trap

The trap here is assuming `print()` requires `__str__`, when `print()` actually falls back to `__repr__` if `__str__` is not defined.

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

✓

Implement `__repr__`, because it provides the unambiguous representation used by the interactive interpreter, `repr()`, and containers, and `__str__` falls back to it when undefined.

`__repr__` is the unambiguous, developer-oriented representation that the interpreter, `repr()`, and containers use, and Python falls back to it for `print()` when `__str__` is absent. Implementing it alone therefore produces `Circle(5)` in every context the scenario mentions. `__str__` is the user-facing alternative, `__format__` governs format-spec handling, and `__init__` has nothing to do with display.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Implement `__repr__`, because it provides the unambiguous representation used by the interactive interpreter, `repr()`, and containers, and `__str__` falls back to it when undefined.

    Why this is correct

    `__repr__` is the canonical developer-facing representation and is what the interactive interpreter, `repr()`, and container displays use. When `__str__` is not defined, `print()` falls back to `__repr__`, so implementing it alone yields `Circle(5)` in every context described. This single method covers both the debugging and printing needs of the scenario without duplication.

  • ✗

    Implement `__str__`, because it is the method the `print()` built-in always calls for any object.

    Why it's wrong here

    `print()` does fall back to `__str__`, but the requirement is a developer-facing representation of the object, which is the conventional role of `__repr__`. Implementing only `__str__` leaves the interactive interpreter and containers showing the default `<__main__.Circle object at 0x...>` form, and `repr()` would not produce `Circle(5)`. The description also cannot be reused to reconstruct the object.

  • ✗

    Implement `__init__` to return a formatted string, because the constructor runs whenever the object is displayed.

    Why it's wrong here

    `__init__` runs once at construction and must return `None`; returning a string raises `TypeError` at instantiation. It has no connection to how an object is displayed, so printing the instance would still show the default representation. The constructor's job is initialisation, not representation, and conflating the two breaks object creation entirely.

  • ✗

    Implement `__format__`, because string formatting is the modern replacement for both `__str__` and `__repr__`.

    Why it's wrong here

    `__format__` controls how an object behaves inside format strings such as f-strings with a format spec, not how `print()` or `repr()` render it. Without a format spec, the default `object.__format__` delegates to `str()`, so the output would still be the default object form. It is not a replacement for the representation methods and does not satisfy the requirement.

Quick reference

AAA Protocol Comparison

ProtocolPort(s)EncryptionTransportPrimary Use
RADIUS1812 / 1813Password onlyUDPNetwork access control
TACACS+49Full packetTCPDevice administration
Diameter3868Full sessionTCP / SCTPCarrier / mobile networks
802.1X—EAP-basedLayer 2Port-based access control

TACACS+ encrypts the entire packet; RADIUS only encrypts the password field — a key exam distinction.

About these practice questions

Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

This PCAP 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 PCAP exam.