列表命令1
2017-04-02
#定义一个moto列表,并读出 motocycles = [‘honda’, ‘yamaha’, ‘suzuki’] print(motocycles) motocycles[0] = ‘ducati’ print(motocycles)
#增加list
motocycles.append(‘kasadi’)
print(motocycles)
#插入
motocycles.insert(0,‘aiya’)
print(motocycles)
#不再使用,del
del motcycles(0)
#print(motocycles)
#还需使用,用pop
first_owned = motocycles.pop(0)
#print(‘The first motocycle I owned was a ’ + first_owned.title() + ‘.’)
#根据值删除元素
motocycles.remove(‘kasadi’)
#print(motocycles)
#排序 print(motocycles) #永久变换顺序
motocycles.sort()
#print(motocycles)
#按照字母相反的顺序
motocycles.sort(reverse = True)
print(motocycles)
#暂时变换顺序
print(sorted(motocycles))
print(motocycles)
#列表倒序
motocycles.reverse()
print(motocycles)
#长度