python 6:list.append(新元素)与list.insert(索引,新元素)(在列表末尾追加新元素、在索引处添加新元素)
1 bicycles = ['trek', 'cannondale', 'redline', 'specialized'] 2 print(bicycles) 3 bicycles.append("honda") #在列表尾追加一个新元素 4 print(bicycles) 5 bicycles.insert(0,"piaggio") #在列表索引处添加一个新元素 6 print(bicycles)
1 运行结果应该如下: 2 ['trek', 'cannondale', 'redline', 'specialized'] 3 ['trek', 'cannondale', 'redline', 'specialized','honda'] 4 ['piaggio','trek', 'cannondale', 'redline', 'specialized','honda']