python里type,object,类的关系
1 # type生成了所有的对象,包含object,list,类..... 2 # type生成了int,int生成了1 3 a = 1 4 print(type(a)) # >> <class 'int'> 5 print(type(int)) # >> <class 'type'> 6 print(type(object)) # >> <class 'type'> object由type生成 7 8 # type生成了str,str生成了'abc' 9 b = 'abc' 10 print(type(b)) # >> <class 'str'> 11 print(type(str)) # >> <class 'type'> 12 13 # object是最顶层的基类 14 print(object.__base__) # >>> None 15 16 # type是一个类,同时type也是一个对象,type的基类是object 17 print(type.__base__) # >> <class 'object'> 18 19 20 class Person(object): 21 pass 22 23 print(type(Person)) # >> <class 'type'> 24 print(Person.__base__) # >> <class 'object'> 25 print(type(type)) #>> <class 'type'>
posted on 2022-01-12 16:04 Shine-Zhong 阅读(36) 评论(0) 编辑 收藏 举报