摘要: class F: def __str__(self): return 'hello china' def __int__(self): return 123res = F()print(res) #结果是hello chinaprint(int(res)) #结果是123创建的对象时,会自动去寻找类 阅读全文
posted @ 2019-12-16 15:46 菜菜_包包 阅读(4173) 评论(0) 推荐(1)
摘要: class F: def __call__(self, *args, **kwargs): print('执行__call__') s = F()s() 先给类创建一个对象,直接通过对象来执行,就会自动去执行类中的__call__函数,如上面的执行结果就是“执行__call__” 阅读全文
posted @ 2019-12-16 15:33 菜菜_包包 阅读(1094) 评论(0) 推荐(0)
摘要: class F: def __init__(self): print('hello china')__init__ 是构造函数,初始化类,每当调用类的时候,就会自动执行这个函数比如:执行 F() 的时候,会自动执行__init__函数,就会自动打印出“hello china” 阅读全文
posted @ 2019-12-16 15:28 菜菜_包包 阅读(4668) 评论(0) 推荐(0)