|
元组特性
不能对元组的值任意更改;元组特性
>>> t1
('fentiao', 4, 'male')
>>> t1[1] = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
对元组分别赋值,引申对多个变量也可通过元组方式分别赋值执行操作并思考
>>> t1
('fentiao', 4, 'male')
>>> name,age,gender=t1
>>> print name,age,gender
fentiao 4 male
>>> a,b,c=(1,2,3)
>>> print a,b,c
1 2 3
注意:C语言中,定义一类型,必须先开辟一存储空间,当后期重新赋值时也一定是整型的;
python中,先在内存上存储数据后,再通过标签去引用。不同的字符串占用不同的存储空间。
>>> str1
'12345'
>>>> 140205776037520
>>> str1 = "abcde"
>>>> 140205776037424
>>> str2 = "12345"
>>>> 140205776037520 |
|
|