filmov
tv
How Do You Print An Object? #shorts #python #pythonforbeginners

Показать описание
How do you print an object?
Well surely it's just print(my_object), right?
Well, it would work but doing that won't give you a very friendly output. Luckily we can do better thanks to the __str__ magic method! With __str__ we can define what Python should display when we print our object.
This video is a super quick sub-20 seconds example of the __str__ method in action.
Well surely it's just print(my_object), right?
Well, it would work but doing that won't give you a very friendly output. Luckily we can do better thanks to the __str__ magic method! With __str__ we can define what Python should display when we print our object.
This video is a super quick sub-20 seconds example of the __str__ method in action.