欢迎光临散文网 会员登陆 & 注册

六大变量——列表

2023-04-12 00:09 作者:树上书  | 我要投稿

创建列表

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


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

list.append('Baidu')

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

list.insert( 32009)

删除元素

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])



六大变量——列表的评论 (共 条)

分享到微博请遵守国家法律