PCAP-31-03 · Question #110
Is it possible to safely check if a class/object has a certain attribute?
The correct answer is C. yes, by using the hassattr ( ) function. Information from Python course, singned by Python Institute: Python provides a function which is able to safely check if any object/class contains a specified property. The function is named hasattr, and expects two arguments to be passed to it: the class or the object being chec
Question
Is it possible to safely check if a class/object has a certain attribute?
Options
- Ayes, by using the hasattr attribute
- Byes, by using the hasattr ( ) method
- Cyes, by using the hassattr ( ) function
- Dno, it is not possible
How the community answered
(46 responses)- A11% (5)
- B4% (2)
- C80% (37)
- D4% (2)
Explanation
Information from Python course, singned by Python Institute: Python provides a function which is able to safely check if any object/class contains a specified property. The function is named hasattr, and expects two arguments to be passed to it: the class or the object being checked; the name of the property whose existence has to be reported (note: it has to be a string containing the attribute name, not the name alone)
Topics
Community Discussion
No community discussion yet for this question.