1.列表举例
print(list(‘hello‘))
2列表元素赋值
x = [1,1,1] x[1] = 2 print(x)
x = [1,1,1] x[4] = 3 print(x) #会报错的,由于为一个不存在的元素进行赋值
3删除元素
name = [‘hello‘,‘world‘,‘python‘,‘love‘] del name[2] print(name) ?
4分片赋值
name = list[‘python‘] print(name) name[2:] = list(‘ar‘) print(name)
name = list(‘Perl‘) name[1:] = list(‘ython‘) print(name)
numbers = [1,5] numbers[1:1] = [2,3,4] print(numbers) #插入元素
numbers = ?[1,2,3,4,5] numbers[1:4] = [] print(numbers)#删除元素