Certified Professional in Python Programming (PCPP-32-101) — Question 39
Which function or operator should you use to obtain the answer True or False to the question "Do two variables refer to the same object?"
Answer options
- A. The == operator
- B. The isinstance() function
- C. The id() function
- D. The is function
Correct answer: D
Explanation
The correct answer is D, the is function, which checks if two variables reference the same object in memory. The == operator compares the values of the objects, not their identities, while isinstance() checks if an object is an instance of a particular class, and id() returns the object's unique identifier but does not directly answer the question.