Vidyalelo
Python · Q18

Advanced OOP Concepts

Programming · Python · question 18

Q18

What is the purpose of the __str__() method in Python classes?

A.
To convert an object to a string
B.
To define the string representation of an object
Answer
C.
To create a copy of an object
D.
To initialize object attributes

Answer: Option B

Solution

Answer: Option B
Solution:
The __str__() method defines the string representation of an object, often used with the str() function.