數(shù)組list操作:
- variable.append( argu ) 在數(shù)組的最后一項(xiàng)添加元素
- slice = list[start: end: stride] 截取出從start(包含)到end(不包含)的元素并返回,stride指間隔數(shù). 此函數(shù)可用于字符串
- list.insert(index,'content') 在序號(hào)前插入指定內(nèi)容
- list.index('content') 查找'content'的序號(hào)
- list.sort() 對(duì)數(shù)組進(jìn)行排序,并修改原數(shù)組
- list.remove('content') 從數(shù)組中移除內(nèi)容,不返回值
- list.pop(index) 移除序號(hào)元素,并返回 index可以是負(fù)數(shù),-1為len(list)-1
- del(list[index]) 刪除元素 并不返回
- range(start, end, stride) 同slice 創(chuàng)建參數(shù)范圍內(nèi)的數(shù)組
- '連接符'.join(list) 講數(shù)組按連接符鏈接,并返回一個(gè)字符串
- enumerate 輸出數(shù)組內(nèi)容以及對(duì)應(yīng)序列號(hào) 一般用于for循環(huán)
for index, item in emumerate(list):
Python匿名函數(shù)
filter(lambda x: x*x, list) (以后待補(bǔ)充)
字典Dict操作:
字典中key和value相互對(duì)應(yīng)
- dict['key'] = 'value' 對(duì)字典進(jìn)行元素添加
- del dict['key'] 刪除字典某個(gè)屬性
- 若字典內(nèi)有包含數(shù)組 可以用 dict['list'][index]來(lái)調(diào)用數(shù)組元素
- dict.items() 遍歷字典,以tuples形式返回key和value
- dict.keys() 返回key
- dict.values() 返回value