Certified Associate in Python Programming (PCAP) — Question 5

Is it possible to safely check if a class/object has a certain attribute?

Answer options

Correct answer: B

Explanation

The correct answer is B because the hasattr() method is the proper way to check for an attribute in Python. Option A incorrectly refers to it as an attribute instead of a method, while option C contains a typo in the method name, and option D is incorrect as it is indeed possible to check for attributes.