class Cat():
def __init__(self,name):
self.name = name
def __str__(self):
return '我是%s' %self.name
tom = Cat('粉条')
print(tom)
运行结果:
我是粉条
python:__str__方法
最新推荐文章于 2024-06-09 01:12:42 发布
class Cat():
def __init__(self,name):
self.name = name
def __str__(self):
return '我是%s' %self.name
tom = Cat('粉条')
print(tom)
运行结果:
我是粉条