python基础数据类型的相关知识点
生活随笔
收集整理的這篇文章主要介紹了
python基础数据类型的相关知识点
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、字符串的函數(shù)join
>>> s = "Hello" >>> s1 = s.join("你好")#將字符串Hello插入到你好中 >>> s1 '你Hello好' >>> s2 = "Tanxu".join("你好嗎")#將字符串Tanxu插入到你好嗎中 >>> s2 '你Tanxu好Tanxu嗎'join可以把列表變成字符串
>>> s3 = "_".join(["Tanxu","is","a","good","student"]) >>> s3 'Tanxu_is_a_good_student'2、list在循環(huán)的時候不能刪,因?yàn)闀淖兯饕?/p> >>> lst = ["Tanxu","is","a","good","student"] >>> for el in lst:lst.remove(el)>>> lst ['is', 'good']
要刪除一個列表:
lst = ["Tanxu","is","a","good","student"]#準(zhǔn)備一個空列表 del_lst = [] for el in lst:del_lst.append(el) #記錄下來要刪除的內(nèi)容 for el in del_lst: #循環(huán)記錄的內(nèi)容lst.remove(el)#刪除原來的內(nèi)容 print(lst) #刪除以周開頭的人 lst1 = ["周杰倫","周星馳","周潤發(fā)","馬化騰","馬云"]del_lst1 = [] for el in lst1:del_lst1.append(el)for el in del_lst1:if "周" in el:lst1.remove(el) print(lst1)3、fromkeys用法:【不會對原來的字典產(chǎn)生影響】
>>> dic = {'a':'123'} >>> s = dic.fromkeys("Hello","你好") #返回一個新的字典 >>> s {'H': '你好', 'e': '你好', 'l': '你好', 'o': '你好'}4、類型轉(zhuǎn)換
元組--》類別? list(tuple)?
列表轉(zhuǎn)換成元組 tuple(list)
list==》str? str.join(list)
str==>list? str.split()
轉(zhuǎn)換成False的數(shù)據(jù):
0,'',None,[],(),{},set()? ==》 False
轉(zhuǎn)載于:https://www.cnblogs.com/tanxu05/p/9902109.html
總結(jié)
以上是生活随笔為你收集整理的python基础数据类型的相关知识点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SCU 4439 Vertex Cove
- 下一篇: 梦到被窝里有蛇什么寓意