国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

詳解Python中的type和object

2020-01-04 14:57:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

type  所有類是type生成的

a = 1b = "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中是一切皆對(duì)象的,類其實(shí)也是對(duì)象,首先type生成了<class 'int'>這個(gè)對(duì)象,<class 'int'>又生成了1這個(gè)對(duì)象,type --> int --> 1

同樣,type生成了<class 'str'>這個(gè)對(duì)象,<class 'type'>又生成了"abc"這個(gè)對(duì)象,type --> str--> “abc”,即type -->生成類對(duì)象 -->對(duì)象

object   所有類的最頂層基類是object

print("int 的基類是:{}".format(int.__bases__))print("str 的基類是:{}".format(str.__bases__))

result:

int 的基類是:(<class 'object'>,)str 的基類是:(<class 'object'>,)<class 'int'>和<class 'str'>的基類都是 <class 'object'> 即:object是最頂層的基類

type與object的關(guān)系(type的基類是object,object是type生成的,object的基類為空)

print("type 的基類是:{}".format(type.__bases__))print("type object:{}".format(type(object)))print("object 的基類是:{}".format(object.__bases__))

result:

type 的基類是:(<class 'object'>,)type object:<class 'type'>object 的基類是:()

Python,type,object

總結(jié)

以上所述是小編給大家介紹的Python中type和object,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到python教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂溪县| 肥西县| 长宁区| 滨海县| 英吉沙县| 遵化市| 嵩明县| 梁河县| 雷山县| 阿尔山市| 莲花县| 泗阳县| 教育| 大安市| 昌图县| 遂川县| 青冈县| 沧州市| 福海县| 丘北县| 衡阳县| 长治县| 金堂县| 通河县| 兴业县| 龙胜| 进贤县| 克拉玛依市| 苗栗市| 南靖县| 徐汇区| 修武县| 息烽县| 青河县| 贵定县| 孝感市| 土默特右旗| 渭南市| 临猗县| 克山县| 怀宁县|