How and When to Use __repr__
In this lesson, you’ll see how to use a second dunder method that controls how ojects are converted to strings, the
class Car: def __init__(self, color, mileage): self.color = color self.mileage = mileage def __repr__(self): return '__repr__ for Car' def __str__(self): return '__str__ for Car'
You’ll learn when
__repr__ is used and how it is different from
__str__. The next lesson will cover the differences between the two in more detail.
Comments & Discussion
Become a Member to join the conversation.