Courseiva

PCAP Object-Oriented Programming Practice Question

A developer writes a class `Vector` and wants `v1 + v2` to return a brand-new `Vector`, while `v1 += v2` should mutate `v1` in place and return it. Which pair of special methods achieves this behaviour?

⚠ Common exam trap

The trap here is believing `__radd__` participates in `v1 += v2`, when it only handles reflected operations where the left operand cannot perform the addition.

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

✓

`__add__` returning a new `Vector`, and `__iadd__` mutating `self` and returning `self`.

Defining `__add__` for the binary plus operator and `__iadd__` for augmented assignment is the idiomatic way to separate non-mutating and in-place semantics. The binary method returns a fresh instance so operands are left untouched, while the in-place method mutates the receiver and returns it so the same object identity is preserved after `+=`. Reflected methods such as `__radd__` serve a different purpose and cannot substitute for either.

Answer analysis

Option-by-option breakdown

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

  • ✗

    `__add__` returning a new `Vector`, and `__radd__` mutating `self` and returning `self`.

    Why it's wrong here

    `__radd__` is only consulted for reflected operations such as `2 + v1` where the left operand's `__add__` fails, so it is never reached in `v1 += v2`. Augmented assignment looks for `__iadd__` first, then falls back to `__add__` plus rebinding. Because `__iadd__` is absent here, `v1 += v2` would rebind `v1` to the new object from `__add__`, not mutate it in place.

  • ✗

    `__add__` mutating `self` and returning `self`, and `__radd__` returning a new `Vector`.

    Why it's wrong here

    `__add__` is expected to be non-mutating in idiomatic Python; mutating inside it would make `v3 = v1 + v2` silently change `v1`, which is surprising and violates the first requirement. `__radd__` handles the reflected case when the left operand does not support the operation, so it never participates in `v1 + v2` for two `Vector` instances. This pair cannot deliver the specified split behaviour.

  • ✓

    `__add__` returning a new `Vector`, and `__iadd__` mutating `self` and returning `self`.

    Why this is correct

    `__add__` is invoked for the binary `+` operator and conventionally returns a new object, which satisfies the first requirement. `__iadd__`, when defined, is called by the augmented assignment `+=`; mutating the instance and returning it makes `v1 += v2` update the existing object rather than rebinding the name to a new one. Together they produce exactly the two distinct behaviours requested.

  • ✗

    `__iadd__` returning a new `Vector`, and `__add__` mutating `self` and returning `None`.

    Why it's wrong here

    `__iadd__` should mutate in place, but returning a new object means the name is rebound to that new object while the original is left mutated, producing confusing double semantics. Worse, `__add__` returning `None` makes `v3 = v1 + v2` set `v3` to `None`, which breaks any subsequent use. This combination contradicts both stated goals.

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.