Python_List

1.List中可以有另一个list

>>> fam2 = [['A', 1], ['B', 2],['C', 3]]
>>> fam2
[['A', 1], ['B', 2], ['C', 3]]

2.list的下标从0开始而且可以逆向取元素

>>> fam = ['liz', 1.73, 'emma', 1.68, 'mom',1.71, 'dad', 1.89]
>>> print fam[0]
liz
>>> print fam[3]
1.68
>>> print fam[-1]
1.89
>>> print fam[-8]
liz
Python_List_第1张图片
image.png
Python_List_第2张图片
image.png

3.list的切片

>>> fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]
>>> fam[3:5]
[1.68, 'mom']
>>> fam[1:4]
[1.73, 'emma', 1.68]
Python_List_第3张图片
image.png

Python_List_第4张图片
image.png

包含起点但是不包含终点
可以不指定具体起点或终点


Python_List_第5张图片
image.png

这样分别对应从起点或直到终点
Python_List_第6张图片
image.png

你可能感兴趣的:(Python_List)