1.将字符串转换为列表
1 #列表的维护
2 #将字符串转换为列表
3 print(list("hello"))
输出结果
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
2.修改元素
1 #修改元素
2 x = [1,2,3,4,5];
3 x[1]=0
4 print(x)
输出结果
[1, 0, 3, 4, 5]
3.增加元素
append()、insert()、extend( )方法
append()方法:在末尾添加元素
s=['how','are','you']
s.append('fine')
print(s)
[‘how’, ‘are’, ‘you’, ‘fine’]
insert()方法:在指定位置添加元素或者列表
s=['how','are','you']
s.insert(3,'fine')
print(s)
[‘how’, ‘are’, ‘you’, ‘fine’]
extend()方法:可迭代,分解成元素添加在末尾。
s = ['how', 'are', 'you']
s.extend('fine')
print(s)
[‘how’, ‘are’, ‘you’, ‘f’, ‘i’, ‘n’, ‘e’]
4.删除
1 #删除remove()删除指定值的元素
2 x = [1