Python编程从入门到实践(2)学习笔记

学习了第三章 关于数组 书上说叫 列表

 1 # 第三章 数组
 2 # 数组 打印的是全部 ['trek','cannondale','redline','specialized']
 3 bicycles = ['trek', 'cannondale', 'redline', 'specialized']
 4 print(bicycles)
 5 
 6 print(bicycles[0])
 7 print(bicycles[0].title())
 8 print(bicycles[-1])
 9 
10 # 数组增删改
11 motorcycles = ['honda', 'yamaha', 'suzuki']
12 print(motorcycles)
13 motorcycles[0] = 'ducati'
14 print(motorcycles)
15 
16 motorcycles.append('zzz')
17 print(motorcycles)
18 
19 motorcycles = []
20 motorcycles.append('honda')
21 motorcycles.append('yamaha')
22 motorcycles.append('suzuki')
23 print(motorcycles)
24 
25 # 插入元素
26 motorcycles.insert(0, 'ducati')
27 print(motorcycles)
28 del motorcycles[0]
29 print(motorcycles)
30 
31 # pop
32 motorcycles = ['honda', 'yamaha', 'suzuki']
33 print(motorcycles)
34 # 最后一个
35 motorcycles.pop()
36 print(motorcycles)
37 # 第一个
38 motorcycles.pop(0)
39 print(motorcycles)
40 
41 # 永久排序
42 cars = ['bmw', 'audi', 'toyota', 'subaru']
43 cars.sort()
44 print(cars)
45 cars.sort(reverse=True)
46 print(cars)
47 
48 # 临时排序
49 cars = ['bmw', 'audi', 'toyota', 'subaru']
50 print(sorted(cars))
51 print(sorted(cars,reverse=True))
52 print(cars)
53 
54 #反转
55 cars = ['bmw', 'audi', 'toyota', 'subaru']
56 cars.reverse()
57 print(cars)
58 len(cars)
59 
60 #越界
61 # print(cars[4])
62 # zz = []
63 # print(zz[-1])
64 
65 

 

上一篇:从来也科技UiBot 6.0社区版全线免费,看RPA距离“人人可用”还有多远


下一篇:Python从入门到实践实操:3.列表