python之列表全紀錄

一、列表 

list_a = ['a1','a2','a3','a2']

1、讀取

list_a[0]

2、取索引

list_a.index('a2')

3、修改

list_a[1] = 'a22'

4、添加

append   追加
insert   插入     list_a.insert(1,'a222')
extend    擴展

list_b =['hello','world']
list_a.extend(list_b)  # list_a 擴展爲  ['a1','a2','a3','hello','world']

5、刪除

remove 刪除   相同的刪除第一個值 list_a.remove('a2')
pop  彈出            list_a.pop(index)
clear 清除爲空   list_a.clear()
del  刪除    del  list_a[1]


6、列表元素個數
len(list_a)

7、元素出現次數

list_a.count('a2')


列表排序

列表.sort()升序排序

列表.sort(reverse=True)降序排序

列表.reverse逆序、反轉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章