python 資料型別 序列 列表

2021-07-04 16:33:57 字數 1233 閱讀 6204

**列表**

list是處理一組有序專案的資料結構,即你可以在乙個列表中儲存乙個序列的專案。

列表是可變型別的資料。

用表示列表,包含了多個以逗號分割開的數字或者字串。

>>> list1 = ['1','chen','陳']

>>> list2 = [1,2,3,4]

>>> list3 = ["str1","str1","22"]

>>> list4 =

>>> list5 = ['chen',18,"male"]

>>> list5[1] = 19

>>> list5

['chen', 19, 'male']

>>> id(list5)

4429403272

>>> list5[1] = 21

>>> id(list5)

4429403272

>>> list5 = ['ch',1,'female']

>>> id(list5)

4429403416

>>> list5[3] = '1234'

traceback (most recent call last):

file "", line 1, in

indexerror: list assignment index out of range

>>> list5

['ch', 1, 'female', '1234']

>>> list5

['ch', 1, 'female', '1234', 'll', '1234']

>>> list5.remove('1234')

>>> list5

['ch', 1, 'female', 'll', '1234']

>>> list5.remove('1234')

>>> list5

['ch', 1, 'female', 'll']

>>> list5.remove(list5[3])

>>> list5

['ch', 1, 'female']

>>> help(list)

>>> list5

['ch', 1, 'female']

>>>

del(list5[1])

>>> list5

['ch', 'female']

Python基礎 核心資料型別 序列 列表

列表方法 extend insert remove popreverse sort count index 列表解析其他 len 索引 索引值必須在序列邊界內,否則會引發錯誤 賦值 元素賦值x i 分片 索引值超出邊界可以工作,python會自動縮放超出邊界的分片使其可用,比如l 3 1 會被縮放成...

python資料型別 列表(序列型別)

序列的取值方法 索引操作符 和 切邊操作符,字串和元組類似,定義完成後,資料的值不可改變,list 空列表 type list list csdn 23,字元搬運工 lst 0 csdn 取值 切片和索引 list 新增 刪除 del list list.remove list list.remov...

python序列資料型別 列表

列表是python內建序列之一,不可雜湊,可修改。下面是本人複習 python基礎教程 magnus lie hetland 第二章的總結筆記。方法運用例子 注意事項 增 在末尾增加乙個值 在末尾增加多個值 extend x.extend y y為有多個值組成的序列 在指定位置插入 insert,切...