"""
21,float()用于將整數(shù)和字符串轉(zhuǎn)換成浮點(diǎn)數(shù)。"""t = float(1)print(t)f ="23"print(float(f))"""
22,format,用{}代替以前的%,格式化輸出字符串
只演示簡(jiǎn)單用法梅鹦,https://docs.python.org/3/library/string.html#formatspec有具體的例子"""print("{:.2f}".format(3.1415926))print("{pre}{un}".format(pre="My name is", un="pyer_up", ))"""
23,frozenset返回一個(gè)凍結(jié)的集合记某,凍結(jié)后集合不能再添加或刪除任何元素苛聘。
語(yǔ)法:frozenset([iterable])
"""print(frozenset([0,1,2,3,4]))"""
24,getattr用于返回一個(gè)對(duì)象屬性值滔吠。
語(yǔ)法:getattr(object, name[, default])
參數(shù)解釋:object -- 對(duì)象寺董。name -- 字符串菊值,對(duì)象屬性外驱。default -- 默認(rèn)返回值,如果不設(shè)定腻窒,在沒(méi)有對(duì)應(yīng)屬性時(shí)昵宇,將觸發(fā) AttributeError。"""classdemoC():var ="good"deftf(self):return2a = demoC()print(getattr(a,"var"))#變量直接打印其值print(getattr(a,"tf","沒(méi)有該對(duì)象"))#返回對(duì)象內(nèi)存地址print(getattr(a,"tfc","沒(méi)有該對(duì)象"))#設(shè)置有默認(rèn)值沒(méi)有報(bào)錯(cuò)print(getattr(a,"tfc"))#報(bào)錯(cuò)"""
25,globals()以字典形式返回當(dāng)前位置所有的全局變量pyrasite-shell pid儿子,可以與進(jìn)程進(jìn)行shell交互瓦哎,獲取,在shell里執(zhí)行g(shù)lobals(),
可以獲取整個(gè)進(jìn)程的全部全局變量蒋譬,比如django應(yīng)用割岛、flask應(yīng)用的變量,而不是獲取某個(gè)模塊的全部全局變量犯助,"""print(globals())#聲明全局變量的另一種形式globals()["test"] ="pyer_up"#使用時(shí)癣漆,globals()["test"]就是一個(gè)整體的變量名"""
26,hasattr()判斷一個(gè)對(duì)象里面是否有name屬性或者name方法,返回BOOL值剂买,有name特性返回True惠爽, 否則返回False。
語(yǔ)法:hasattr(object, name)
"""classdemoB():var ="good"deftf(self):return2a = demoB()print(hasattr(a,"var"))print(hasattr(a,"tf"))print(hasattr(a,"aa"))"""
27,hash()獲取取一個(gè)對(duì)象(字符串或者數(shù)值等)的哈希值瞬哼。"""print(hash("123321"))
"""
28,help(o)用于查看函數(shù)或模塊用途的詳細(xì)說(shuō)明婚肆。"""print(help(list))
"""
29,hex()用于將10進(jìn)制整數(shù)轉(zhuǎn)換成16進(jìn)制,以字符串形式表示坐慰。"""print(hex(123))print(hex("123"))#如果不是數(shù)字较性,會(huì)報(bào)錯(cuò),print(hex(12.1))#只能是整數(shù)结胀,浮點(diǎn)數(shù)也會(huì)報(bào)錯(cuò)"""
30,id()回對(duì)象的唯一標(biāo)識(shí)符赞咙,標(biāo)識(shí)符是一個(gè)整數(shù)。CPython 中 id() 函數(shù)用于獲取對(duì)象的內(nèi)存地址把跨。"""a ="pyer_up"print(id(a))