1.

What is setattr() used for?(a) To access the attribute of the object(b) To set an attribute(c) To check if an attribute exists or not(d) To delete an attributeThis question was addressed to me in exam.The doubt is from Classes and Objects topic in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python

Answer»

The CORRECT option is (B) To SET an attribute

For explanation: setattr(obj,name,value) is used to set an attribute. If attribute doesn’t exist, then it would be CREATED.



Discussion

No Comment Found

Related InterviewSolutions