六大变量——列表|世界要闻

创建列表

lst=[] #以逗号分割各项,可以是数值、字符串等

A用list.appand()在末尾添加

list.append('Baidu')


(资料图片)

B用list.insert(x,y)#x为对象y需要插入的索引位置。y要插入列表中的对象。

list.insert( 3, 2009)

删除元素

del list[2]

删除整个列表

del list

用索引

list = ['Google', 'Runoob', 1997, 2000]

list[2] = 2001

用索引、中括号方式(左闭右开)

list = ['red', 'green', 'blue', 'yellow', 'white', 'black']

print( list[0] )

print(list[0:4])

标签:

X 广告
X 广告

Copyright ©  2015-2022 西方舞蹈网版权所有  备案号:沪ICP备2020036824号-7   联系邮箱:5 626 629 @qq.com