__str__ 以及 __repr__

code

class mytest():
    def __str__(self):
        return "hello" 
    def __repr__(self):
        return "world"

a=mytest()
print(a)
print(str(a))
print(repr(a))

outputs

macname@MacdeMBP Desktop % python3 test_0823.py 
hello
hello
world
macname@MacdeMBP Desktop % 

 

 

 

 

 

 

 

 

posted @ 2020-09-13 15:42  anobscureretreat  阅读(240)  评论(0编辑  收藏  举报