0
What is difference __repr__ and __str__?
5 Answers
+ 2
String is readable and repr is unambiguous. reor is more for debugging purposes. In my example you can copy the repr and actually run it in the console to recreate the datetime object.
+ 2
If you have __repr__ in your class then you can print your object in interpreter session also in IDLE but if you define __str__ in class and don't define __repr__ in class then you can only print your object in IDLE not in interpreter session. mostly __repr__ is debugging aid.
Also watch this.
https://youtu.be/aIdzBGzaxUo
+ 1
import datetime
today = datetime.date.today()
print(str(today))
print(repr(today))
+ 1
Thanks)
0
It's cool. Thanks!