六大变量——列表
创建列表
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])