1. Tuple
>>> x=(1)
>>> type(x)
<class 'int'>
>>> x=(1,)
>>> type(x)
<class 'tuple'>
>>>
当数组只有一个元素时你必须这样定义才可以 ,另外数组内容是不可变的,不可以为其中的元素赋值,不然会出错。
>>> x[0]=2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
定义数组
可以这样定义
>>> x=1,2,3,4,5>>> x=(1,2,3,4,5)
>>> max(x)
5
>>> min(x)
1
也可以这样
>>> x=(1,2,3,4,5)
另外 数组还支持,从后往前访问 如
>>> x[-1]
>>>5
就是这样
2 List
list 就不一样了,list是可变的 他是这样定义
>>> l=[]
>>> l[0]=1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> l=[1,23,3]
>>> l
[1, 23, 3]
>>> l[1]=2
>>> l
[1, 2, 3]
list是可变 还需要深入了解其特性才可以