1 #Author : Kelvin
 2 #Date : 2019/1/21 16:19
 3 class App:
 4     def __init__(self,name):
 5         self.name=name
 6     # def __str__(self):
 7     #     return "名字是%s"%self.name
 8     # def __repr__(self):
 9     #     return "repr方法!"
10 a=App("kelvin")
11 print(a)
12 
13 """
14 如果类中没有str和repr方法则打印:<__main__.App object at 0x00000266BDFD2F60>
15 如果类中同时存在str和repr方法则打印str方法的返回值
16 如果类中存在其一,则打印该方法的返回值。
17 """

相关文章: