what if you also have __str__ . can you use __repr__ to change the it to any type() ? can you have __repr__ define a class representation as bytes but then also use __str__ to define string return value?
the simplest way to go about it is to understand the goal of both of the methods: 1) __repr__ has to return a string that is unambiguous i.e. it should return information on both the type of the object and the value that it holds. 2) __str__ has to return a string that is printable i.e. it should return a value so that it looks good when printed. These are the conventions that are followed. However, when you are writing custom code you can always make everyone else's life difficult by returning non standard values which is not recommended.
Clear and straight to the point! Thank you
love the simple explanation!!
Best explanation for repr
great explanation. finally i get it. keep it up the good work!
true finally, i too got it! but need to practice
Best explanation 👌
Very good tutorial
Just found your channel. Thanks!
youre the best
nice nice
Thanks!!
clear!
Awesome....
what if you also have __str__ . can you use __repr__ to change the it to any type() ? can you have __repr__ define a class representation as bytes but then also use __str__ to define string return value?
I don't get your question
the simplest way to go about it is to understand the goal of both of the methods:
1) __repr__ has to return a string that is unambiguous i.e. it should return information on both the type of the object and the value that it holds.
2) __str__ has to return a string that is printable i.e. it should return a value so that it looks good when printed.
These are the conventions that are followed. However, when you are writing custom code you can always make everyone else's life difficult by returning non standard values which is not recommended.