..
列表用中括号表示:
list = [ ]
1.append(数据):把添加的元素放进列表里
list = [ ]
list.append("老王")
print(list)
list ['老王']
2.insert(数据,索引):把添加的元素根据索引放在该索引的位置上
list = ['老王']
list.insert(0,'老宋')
print(list)
list = ['老王','老宋' ]
extend增:
list = ['老张']
list1 = ['老王' '老宋']
list.extend(list1)
print(list)
list = [老王 ,老宋 ,老张]
1.remove(列表里的数据):指定删除某个元素:
list = ['老王','老宋','老张']
list.remove('老宋')
print(list)
list = ['老王','老张']
pop():默认删除最后一个
list = ['老王','老宋','老张']
list.pop()
print(list)
list = ['老王','老宋']
pop(索引):删除索引位置上的那个值
list = ['老王','老宋',]
list.pop(0)
print(list)
修改:list [索引] = 数据
list = ['老王','老宋','老张','老赵']
list[1] = '老马'
print(list)
list = ['老王','老马','老张','老赵']
查找:list [索引]
list = ['老王',`'老马'`,'老张','老赵]
list [2]
print(list)
list = ['老张']
网友评论