I have a class, Matrix, i would like when print is called on this class, instead of printing
<main.Matrix instance at 0x7f41fb17de18>
I would like to be able to control the output something like
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
In C++ i would just overload the << operator. How can i do this in python 3?
If you want to produce a printable output, implement
__str__. You can also implement__repr__but is usually used to create a more technical representation instead of just a human-readable output.