Python | Classes Quiz | Question 20

Last Updated :
Discuss
Comments

What is the purpose of the __str__ and __repr__ methods in a Python class?

__str__ is used for creating string representations of instances, while __repr__ is used for debugging.

__str__ is used for debugging, while __repr__ is used for creating string representations of instances.

Both __str__ and __repr__ serve the same purpose.

__str__ and __repr__ are not valid methods in Python.

Share your thoughts in the comments