What does the __str__ method do in a Python class?
Correct answer
A. Convert an object to a string
17 views
A. Convert an object to a string
17 views
The __str__ method returns a string representation of an object. Python calls it whenever you use print(obj) or str(obj), so it should return something readable for end users.
Its companion __repr__ gives an unambiguous representation aimed at developers and debugging.
Practise more Computer Science MCQs with answers and explanations on MCQsExam.com.
Not sure why the answer is A? Ask here and get an explanation.