motorcycles = ["honda", "yamaha", "suzuki"] print(motorcycles) del motorcycles[1] print(motorcycles) 输出为: ['honda', 'yamaha', 'suzuki'] ['honda', 'suzuki']…
motorcycle = ["honda", "yamaha", "suzuki"] last_owned = motorcycle.pop() print("The last motorcycle I owned was a " + last_owned.title() + ".") 输出为: The last motorcycle I owned was a Suzuki.…
>>> cars = ["bmw", "audi", "toyota", "subaru"] >>> len(cars) 4…
# -*- coding: GBK -*- #reverse: 相反的 cars = ["bmw", "audi", "toyota", "subaru"] print(cars) cars.reverse() print(cars) 输出为: ['bmw', 'audi', 'toyota', 'subaru'] ['subaru', 'toyota', 'audi', 'bmw']…
# -*- coding: GBK -*- cars = ["bmw", "audi", "toyota", "subaru"] print("这是以前的列表:") print(cars) print("\n这是排序后的列表:") print(sorted(cars)) print("\n再次核对是否改变以前的列表:") print(cars) 输出为: 这是以前的列…
cars = ["bmw", "audi", "toyota", "subaru"] cars.sort() print(cars) 输出为: ['audi', 'bmw', 'subaru', 'toyota'] 反向排序: cars = ["bmw", "audi", "toyota", "subaru"] cars.sort(reverse…
# -*- coding: GBK -*- liebiao = ["zhang", "li", "wang", "zhou"] print("wo yao qing :" + liebiao[0] + "." + liebiao[1] + "." + liebiao[2] + "." + liebiao[3]) 输出为: wo yao qing :…
motorcycles = ["honda", "yamaha", "suzuki", "ducati"] print(motorcycles) motorcycles.remove("ducati") print(motorcycles) 输出为: ['honda', 'yamaha', 'suzuki', 'ducati'] ['honda', 'yamaha', 'suzuki'] 2. motorc…
motorcycles = ["honda", "yamaha", "suzuki"] first_owned = motorcycles.pop(0) print("The first motorcycle I owned was a " + first_owned.title() + ".") 输出为: The first motorcycle I owned was a Honda.…
motorcycles = ['honda', 'yamaha' ,'suzuki'] motorcycles.insert(0, "ducati") print(motorcycles) 输出为: ['ducati', 'honda', 'yamaha', 'suzuki'] 2: motorcycles = [] motorcycles.append("honda") motorcycles.append("yamaha") motorcyc…