Matrix Python3类的控制打印输出

Matrix Python3类的控制打印输出,matrix,python-3.x,operator-overloading,Matrix,Python 3.x,Operator Overloading,我有一个类,Matrix,我想在这个类上调用print,而不是print 我希望能够像这样控制输出 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 在C++中,如果要生成可打印的输出,则只需重载。您也可以实现,但通常用于创建更具技术性的表示,而不仅仅是人类可读的输出 >>> class MyType: def __str__ (self): return 'foo' >>> print(MyType(

我有一个类,Matrix,我想在这个类上调用print,而不是print

我希望能够像这样控制输出

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

<>在C++中,如果要生成可打印的输出,则只需重载。您也可以实现,但通常用于创建更具技术性的表示,而不仅仅是人类可读的输出

>>> class MyType:
        def __str__ (self):
            return 'foo'
>>> print(MyType())
foo