[Tutor] __str__ Vs __repr__

Manprit Singh manpritsinghece at gmail.com
Tue Nov 30 12:05:14 EST 2021


Dear Sir,

After assigning a value to a variable, Lets say variable is a, and the
value assigned to it is 5,
On an interactive shell after writing a and then hitting Enter key, it
prints the value of a, that is 5, This happens due to __str__ or __repr__?

What should I use(__str__ or  __repr__) if I want something to be printed
when I print an object of a user defined class ?


More information about the Tutor mailing list