2、获取列表元素个数
>>> len(list1)
4
3、访问列表中的值
(1)使用索引来访问列表中的值,列表的索引从0开始:
>>> list1[0]
'python'
>>> list1[1]..."", line 1, in
IndexError: list index out of range
注意:当索引超出范围时,Python会报一个IndexError错误...,所以,要确保索引不要越界,记得最后一个元素的索引是len(list1) - 1。...1, in
IndexError: list index out of range
当然,倒数第5个元素已越界,需要注意一下。...)
>>> tup2
(1, 2, 3, 4)
>>> tup3 = ('a', 'b', 'c', 'd')
>>> tup3
('a', 'b', 'c', 'd')
注意:元组中只包含一个元素时,