python-011列表list类型、方法

 1 列表:几个元素的集合;
 2 元祖:几个字符的集合;
 3 
 4 
 5 ##########  列表  #########
 6 name_list = ["eire","alex","tony"]
 7 # 索引
 8 print(name_list[0])
 9 # 切片
10 print(name_list[1:2])name_list = ["eire","alex","tony"]
11 name_list.append("seven")
12 print (name_list)
13 print (name_list.count('seven'))
14 teme = ["11","22","33"]
15 name_list.extend(teme)
16 print(name_list)
17 print (name_list.index('alex'))
18 name_list.insert(1,'shin')
19 print (name_list)
20 a1 = name_list.pop()
21 print (name_list)
22 print (a1)
23 name_list.remove('seven')
24 print (name_list)
25 name_list.reverse()
26 print (name_list)
27 # 循环
28 for i in name_list:
29     print (i)
30     
31 # 列表内部提供的其他功能
32 # 1.append :后面追加
33 name_list.append("save")
34 print (name_list)
35 # 2.count:统计元素出现的次数
36 name_list = ["eire","alex","tony"]
37 name_list.append("seven")
38 name_list.append("seven")
39 name_list.append("seven")
40 print (name_list)
41 # 3.extend 扩展  # iterable 可迭代的
42 name_list = ["eire","alex","tony"]
43 name_list.append("seven")
44 print (name_list)
45 print (name_list.count('seven'))
46 teme = ["11","22","33"]
47 # 扩展、批量添加
48 name_list.extend(teme)
49 print(name_list)
50 # 获取指定元素的索引位置
51 print (name_list.index('alex'))
52 # 向指定元素位置插入数据
53 name_list.insert(1,'shin')
54 print (name_list)
55 # 在原列表中移除最后一个元素,并将其赋值给 a1
56 a1 = name_list.pop()
57 print (name_list)
58 print (a1)
59 # 移除某个元素
60 name_list.remove('seven')
61 print (name_list)
62 # 翻转
63 name_list.reverse()
64 print (name_list)

 

上一篇:170112-机械臂moveit!抓取


下一篇:seven