motorcycles=["honda","yamaha","suzuki"]
first_owned=motorcycles.pop(0)#pop()方法可指定删除特定索引位置值print("The first owned was a "+first_owned.title()+"!")
根据值删除元素
motorcycles=["honda","yamaha","suzuki","ducati"]
too_expensive="ducati"
motorcycles.remove(too_expensive)#remove()方法根据元素值删除列表中元素print(motorcycles)print("\nA "+too_expensive.title()+" is too expensive for me!")
cars=["bmw","audi","toyota","subaru"]print("Here is the ordinary list:")print(cars)print("\nHere is the sorted list:")print(sorted(cars))#函数sorted()对列表进行临时排序print("\nHere is the ordinary list again:")print(cars)