Examveda

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

C. To create a copy of an object

D. To initialize object attributes

Answer: Option B

Solution (By Examveda Team)

The __str__() method defines the string representation of an object, often used with the str() function.

This Question Belongs to Python Program >> Advanced OOP Concepts

Join The Discussion

Related Questions on Advanced OOP Concepts

What is inheritance in OOP?

A. Creating new objects from existing ones

B. Allowing objects to share attributes and methods

C. Restricting access to object attributes

D. Converting classes into objects