Python自学之collection

# 定义数组
x = [31.8, 33.9, 35.0, 33.9, 33.8, 33.0, 33.0, 34.4, 36.5, 38.0, 39.3, 40.7, 41.7, 41.4, 40.7, 39.9]
# 数组遍历
for a in x:
     print (a)
 # 数组遍历
for i in range(0, len(x)):
     print (i, x[i])
 #map
information=['liusen',25]
print(information[1]+1)
#负数表示从另一边查找
print(x[-1])
print(x[3:-3])
print(x[3:-3:2])
x=[1,2,3]
y=[4,5,6]
print(x+y)
s=[1]*12
print(s)
print(len(s))
m='python'*5
print(m)

实验结果:

31.8
33.9
35.0
33.9
33.8
33.0
33.0
34.4
36.5
38.0
39.3
40.7
41.7
41.4
40.7
39.9
0 31.8
1 33.9
2 35.0
3 33.9
4 33.8
5 33.0
6 33.0
7 34.4
8 36.5
9 38.0
10 39.3
11 40.7
12 41.7
13 41.4
14 40.7
15 39.9
26
39.9
[33.9, 33.8, 33.0, 33.0, 34.4, 36.5, 38.0, 39.3, 40.7, 41.7]
[33.9, 33.0, 34.4, 38.0, 40.7]
[1, 2, 3, 4, 5, 6]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
12
pythonpythonpythonpythonpython

你可能感兴趣的:(Python)