python列表操作。

2022-09-03 21:33:22 字數 957 閱讀 7667

通過索引操作列表:

n = [1, 3, 5

]# add your code below

s = n[1

]print s

這裡n中有三個元素,索引是從0開始計算。例項中的1代表的從0開始。

通過索引操作列表:

n = [1, 3, 5

]# do your multiplication here

print n

n[1] = n[1] * 5

print n

-----------------------------------------------另外一種寫法。

n = [1, 3, 5

]# do your multiplication here

print n

n[1] *= 5

print n

n = [1, 3, 5]4

here4)

print n

.pop .remove del用法:

n = [1, 3, 5

]# remove the first item

inthe list here

n.pop(0)

print n

這裡的0代表索引。

n = [1, 3, 5

]# remove the first item

inthe list here

n.remove(1)

printn

這裡的一代表的是元素。

n = [1, 3, 5

]# remove the first item

inthe list here

del (n[0])

print n

這裡的0代表的索引。

python列表建立操作 python列表操作

建立列表 sample list a 1,a b python 列表操作 sample list a b 0,1,3 得到列表中的某乙個值 value start sample list 0 end value sample list 1 刪除列表的第乙個值 del sample list 0 在列...

python列表建立操作 python列表操作

列表是最常用的python資料型別,它可以作為乙個方括號內的逗號分隔值出現。列表的資料項不需要具有相同的型別。如 list a b 2,5,1 1 新建列表 stus 建立空列表 stus1 list 建立空列表 print stus print stus1 stus 范冰冰 維達 soon 上述 ...

python 列表操作

list 一種順序儲存結構,序列的一種,列表元素可以是任何型別,類似陣列,引用型別。格式定義 olist 1,str 定義乙個空的list olist 獲取列表元素個數 len olist 刪除乙個列表 del olist 刪除乙個列表元素 del list i 支援 olist1 olist2 列...