>>> a = []
>>> a
[]
>>> type(a)
<class 'list'>
>>>
>>> b = list()
>>> b
[]
>>> type(b)
<class 'list'>
>>>
例2
>>> a = [100]
>>> a
[100]
>>> type(a)
<class 'list'>
>>>
>>> b = [1, 2, 3, 4, 5]
>>> b
[1, 2, 3, 4, 5]
>>> type(b)
<class 'list'>
>>>
常用操作
访问:索引从 0 开始
分片/切片:截取列表的一部分或全部,索引左闭右开
访问
例3
>>> a = [0, 1, 2, 3, 4]
>>> a[0]
0
>>> a[2]
2
>>> a[-1]
4
>>> a[5]
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a[5]
IndexError: list index out of range
>>>