-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.py
63 lines (49 loc) · 1.19 KB
/
array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#取最后一个元素
bicycles = ['trek','cannondale','redline','specialized']
print(bicycles[-1])
#取元素、调用title方法
message = "My first bicycle was a " + bicycles[0].title()
print(message)
motorcycles = ['honda','yamaha','suzuki']
print(motorcycles)
#修改元素
motorcycles[0] = 'ducati'
print(motorcycles)
#添加元素
motorcycles.append('toyota')
print(motorcycles)
#空列表添加元素
motorcycles1 = []
motorcycles1.append('honda')
motorcycles1.append('yamaha')
motorcycles1.append('suzuki')
print(motorcycles1)
#列表中插入元素
motorcycles1.insert(0,'ducati')
print(motorcycles1)
#弹出末尾元素
poped_motorcycle = motorcycles1.pop()
print(motorcycles1)
print(poped_motorcycle)
#pop任意位置元素
print(motorcycles1.pop(1))
print(motorcycles1)
#根据值删除元素
motorcycles1.remove('ducati')
print(motorcycles1)
#按字母sort排序
cars = ['bmw','audi','toyota','subaru']
cars.sort()
print(cars)
#按字母反向排序
cars.sort(reverse=True)
print(cars)
#使用sorted进行临时排序
print(sorted(cars))
print(cars)
#反转列表元素排列顺序
cars1 = ['bmw','audi','toyota','subaru']
cars1.reverse()
print(cars1)
#获取列表长度
print(len(cars1))