+ 1
Why we use __repr__ in python classes?
I m using __repr__ as function for clasess in python. When i create the object of the class and simply print it ,return me the value that i put in the __repr__ function. I wonder if i use another class name and print the object simply , it return me the adderss value.
1 Antwort
+ 8
__repr__ is a magic method or they also call it dunders. This method is called whenever you try to print an object of a class.
If you create your custom class then you must override this method in order to print an object of that class. If you're not overriding this method then printing an object will print its address in the memory.