点击查看【bilibili】
当使⽤用print输出对象的时候,默认打印对象的内存地址。如果类定义了了 str ⽅方法,那么就会打印从
在这个⽅方法中 return 的数据。
实例代码如下:
class Wash():
def __init__(self):
self.width = 400
self.height = 800
def __str__(self):
return "这是一个返回值,返回的是具体内容"
haier1 = Wash()
print(haier1)
运行结果如下:
点击查看【bilibili】
当使⽤用print输出对象的时候,默认打印对象的内存地址。如果类定义了了 str ⽅方法,那么就会打印从
在这个⽅方法中 return 的数据。
实例代码如下:
class Wash():
def __init__(self):
self.width = 400
self.height = 800
def __str__(self):
return "这是一个返回值,返回的是具体内容"
haier1 = Wash()
print(haier1)
运行结果如下:
让时间为你证明