列表的拼接:extend方法
增加元素append
插入指定位置的元素:insert
list=["1","qre","ajjfj"]
list.append("hahah")
list.append("[adksf]")
print(list)
list.insert(1,"dddddd")
print(list)
list.extend(["ttt","uu","ppp"])
print(list)
['1', 'qre', 'ajjfj', 'hahah', '[adksf]']
['1', 'dddddd', 'qre', 'ajjfj', 'hahah', '[adksf]']
['1', 'dddddd', 'qre', 'ajjfj', 'hahah', '[adksf]', 'ttt', 'uu', 'ppp']
对于字典
总结字典的增删改查的方法:
print( "----------------------");
#dict的用法:
dict={"gsj":22,"a":"ab"}
#添加元素
dict["a"]=789
dict["new"]="newkey"
print(dict)
xx={"qwe":"123",123:678}
dict.update(xx);
print("进行拼接")
print(dict)
print(dict.pop("gsj"))
print(dict)
del(dict["a"])
print(dict)
dict.clear()
print(dict)
----------------------
{'gsj': 22, 'a': 789, 'new': 'newkey'}
进行拼接
{'gsj': 22, 'a': 789, 'new': 'newkey', 'qwe': '123', 123: 678}
22
{'a': 789, 'new': 'newkey', 'qwe': '123', 123: 678}
{'new': 'newkey', 'qwe': '123', 123: 678}
{}