L = ['a', 'b', 3]
如同数据结构中的线性表,python中list元素也可以按照索引被访问。如同线性表,list的首元素索引号也为0。
>>>print L[0]
a
>>>print L[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
"IndexError: list index out of range":即索引号超出list的索引范围。所以在使用索引进行访问list列表时,注意不要越界。