python列表操作 賦值

2021-07-25 03:05:38 字數 772 閱讀 4726

1、元素賦值

x=[1,1,1]

x[1]=2

print x

[1, 2, 1]

2、分片賦值

a=[1,2,3,4,5]

a[1:4]=['a']

print a

a[1:3]=

print a

[1, 'a', 5]

[1]3、賦空值

x=[none]*3

print x

len(x)

[none, none, none]

out[217]: 3

------------------問題-----------

互動式直譯器(如ipython)和其他開發環境(如:spyder)具體有啥區別,除了乙個能直接出結果,乙個需要列印結果,二者在使用規則上有何不同,現遇到問題如下:

元素變列表 list()

在ipython中有結果:

in [9]: list('python')

out[9]: ['p', 'y', 't', 'h', 'o', 'n']

在spyder中報錯:

print list('python')

traceback (most recent call last):

file "", line 1, in

print list('python')

typeerror: 'list' object is not callable

如果哪位朋友看到,希望可以幫忙回答,在此感謝~

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 列...