__str and __repr

For this blog, will try to keep short only. str and repr are used to get a string representation.
The difference is that str will give output for the user end but repr is generally used for debugging stage as repr gives the full description of that object along with string representation. All this will be clear to you from examples. Let’s discuss some examples -:

str and repr

String variable and Date and Time object

You can also create __str__ and __repr__ function as str() uses __str__ and repr() uses __repr__  for your custom class as well. Here we are not discussing it in details.

Hope you are able to differentiate between repr and str now. Stay tuned! Keep learning with us.

Close Menu