PCAP Object-Oriented Programming Practice Question
A class `Point` has an `__init__` that sets `self.x` and `self.y`. They want to compare points by equality (i.e., `p1 == p2` should work correctly). Which method should they implement?
⚠ Common exam trap
Python Institute often tests the distinction between Python 2's `__cmp__` and Python 3's `__eq__`; the trap here is that candidates familiar with older Python may incorrectly choose `__cmp__`, not realizing it is obsolete in Python 3.
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
✓
`__eq__`
In Python, the `__eq__` method is the correct way to define equality comparison for objects. When you implement `__eq__(self, other)`, it is automatically called by the `==` operator, allowing `p1 == p2` to return a Boolean based on custom logic (e.g., comparing `self.x` and `self.y`). This is the standard Python protocol for equality testing.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
`__same__`
Why it's wrong here
There is no `__same__` method in Python's data model. The language defines a fixed set of special method names (dunder methods) for operator overloading, and equality is specifically handled by `__eq__`. Defining a method named `__same__` would simply create an ordinary method, and it would have no effect on the behavior of the `==` operator or any other built-in operation.
- ✓
`__eq__`
Why this is correct
`__eq__` is the correct special method to override for the equality operator (`==`) in Python. By implementing `__eq__` in the `Point` class, you can compare two point instances based on their coordinate attributes (e.g., `self.x == other.x and self.y == other.y`) rather than by their identity. This is the standard, documented approach for value equality in Python's object model.
- ✗
`__compare__`
Why it's wrong here
No special method named `__compare__` exists in Python. Some programming languages provide a single generic compare method (like Java's `compareTo`), but Python uses a rich comparison protocol consisting of separate dunder methods: `__eq__`, `__ne__`, `__lt__`, `__le__`, `__gt__`, and `__ge__`. Therefore, defining `__compare__` would not be recognized by the interpreter for any comparison operation.
- ✗
`__cmp__`
Why it's wrong here
`__cmp__` was the comparison method used in Python 2, where it returned a negative, zero, or positive integer to indicate ordering. In Python 3, `__cmp__` is no longer supported; the language requires rich comparison methods such as `__eq__` and `__lt__` instead. Even if you define `__cmp__` in a Python 3 class, it will be ignored when using `==` or other comparison operators.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.