Python对列表的操作
#访问列表元素food =['bunana','apple','orange']print(food[0])print(food[1])print(food[2])print("hello "+food[0]+"!")print("hello "+food[1]+"!")print("hello "+food[2]+"!") #修改food =['bunana','apple','orange']food[0]='hahaha'print(food)#增加food =['bunana','apple','orange']#1、末尾增加food.append('西瓜')food.append('西红柿')print(food)#2、在列表中插入元素food.insert(0,"土豆")print(food)#3、删除#如果知道要删除的元素在列表中的位置,可使用del 语句。del food[0]print(food)#方法pop() 可删除列表末尾的元素,并让你能够接着使用它a=food.pop()print(food)print(a)#remove根据值删除元素food.remove("西瓜")print(food)#永久排序food.sort()print(food)#反转food.reverse()print(food)#长度print(len(food))#遍历#创建一个列表