type 所有类是type生成的
a = 1
b = "abc"
print("type a:{}".format(type(a)))
print("type int:{}".format(type(int)))
print("type b:{}".format(type(b)))
print("type str:{}".format(type(str)))
result:
type a:<class 'int'> type int:<class 'type'> type b:<class 'str'> type str:<class 'type'>
在python中是一切皆对象的,类其实也是对象,首先type生成了<class 'int'>这个对象,<class 'int'>又生成了1这个对象,type --> int --> 1
同样,type生成了<class 'str'>这个对象,<class 'type'>又生成了"abc"这个对象,type --> str--> “abc”,即type -->生成类对象 -->对象
所有类的最顶层基类是
print("int 的基类是:{}".format(int.__ s__))
print("str 的基类是:{}".format(str.__ s__))
result:
int 的基类是:(<class ' '>,) str 的基类是:(<class ' '>,) <class 'int'>和<class 'str'>的基类都是 <class ' '> 即: 是最顶层的基类
type与 的关系(type的基类是 , 是type生成的, 的基类为空)
print("type 的基类是:{}".format(type.__ s__))
print("type :{}".format(type( )))
print(" 的基类是:{}".format( .__ s__))
result:
type 的基类是:(<class ' '>,) type :<class 'type'> 的基类是:()
总结
以上所述是小编给大家介绍的Python中type和 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
继续阅读与本文标签相同的文章
上一篇 :
详解微信JS-SDK选择图片遇到的坑
下一篇 :
如何在AI芯片创业热潮中生存下来?
-
奇点云发布《大数据咨询方法论白皮书》,首次定义大数据咨询
2026-05-17栏目: 教程
-
Android studio如何连接三星手机
2026-05-17栏目: 教程
-
在SAP除了使用Cordova生产移动应用外,还有这种方式
2026-05-17栏目: 教程
-
如何使用点击超链接的方式打开Android手机上的应用
2026-05-17栏目: 教程
-
SAP Marketing Cloud功能简述(一) : Contacts和Profiles
2026-05-17栏目: 教程
