0
点赞
收藏
分享

微信扫一扫

Python 改写__str__

梯梯笔记 2022-02-09 阅读 33


# 一般情况
class TestClass:
def __init__(self):
self.name = 'paomo'
t = TestClass()
print(t)
# <__main__.TestClass object at 0x10f1e5670>


# 改写 __str__ 方法
class TestClass:
def __init__(self):
self.name = 'paomo'

def __str__(self):
return self.name
t = TestClass()
print(t)



举报

相关推荐

0 条评论