Courseiva

PCAP Object-Oriented Programming Practice Question

Which TWO of the following are special methods in Python?

⚠ Common exam trap

Python Institute often tests the distinction between actual special methods (like `__init__` and `__str__`) and arbitrary dunder-named attributes that are not part of Python's language specification, leading candidates to mistakenly think any name with double underscores is a special method.

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

✓

`__init__`

In Python, special methods (also called dunder or magic methods) are predefined methods with names of the form __name__ that the interpreter invokes implicitly to implement language features. Option C, `__init__`, is the initializer special method that Python calls automatically when an instance is created, e.g., `obj = MyClass()`, to set up the object's initial state. Option D, `__str__`, is the special method that Python calls by default by `str(obj)` and `print(obj)` to produce a human-readable string representation of the object. By contrast, options A (`__bar__`) and E (`__foo__`) merely follow the double-underscore naming pattern but are not defined by the Python data model as special methods, so they are ordinary attributes. Option B, `__main__`, is not a method at all; it is the name of the top-level execution scope (the value of `__name__` for the main script) and the conventional module name checked with `if __name__ == "__main__":`.

Answer analysis

Option-by-option breakdown

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

  • ✗

    `__bar__`

    Why it's wrong here

    A dunder name alone does not make a special method; Python reserves specific identifiers such as __init__ or __str__, and __bar__ is merely a user-defined name with no interpreter hook. It tempts because the double-underscore convention visually mimics genuine special methods, which are the correct answer when the exact reserved name is listed.

  • ✗

    `__main__`

    Why it's wrong here

    __main__ is a module-level string attribute holding the top-level script's name, not a method defined on a class. It tempts because it appears in the familiar if __name__ == '__main__' idiom, which is the correct context for it, but it never participates in operator overloading or object protocol dispatch.

  • ✓

    `__init__`

    Why this is correct

    `__init__` is a special (dunder) method automatically invoked by Python when an instance is created, initialising the object's attributes. It satisfies the stem's requirement for special methods, which are defined by reserved double-underscore names and called implicitly by the interpreter rather than by explicit invocation.

  • ✓

    `__str__`

    Why this is correct

    __str__ is a special method, called by str() and print() to produce a readable string representation. Its double-underscore naming identifies it as part of Python's data model, satisfying the question's requirement for a genuine special method.

  • ✗

    `__foo__`

    Why it's wrong here

    __foo__ matches the dunder naming pattern but is not a reserved Python special method; the interpreter only invokes names it explicitly defines, such as __len__ or __eq__. It tempts because any double-underscore wrapper looks like a magic method, and such names are the correct answer only when they appear in Python's documented data model.

About these practice questions

One of 421 original PCAP 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

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.