python之元组
上一篇 /
下一篇 2016-10-22 17:46:05
/ 个人分类:python
元组 不可更改的数据序列 不能改变元组的值
>>> filler=("a","b","c","d")
>>> print filler
('a', 'b', 'c', 'd')
>>> c=(filler,"fa") #其它元组引用元组
>>> c
(('a', 'b', 'c', 'd'), 'fa')
print(c)
空元组:
a=()
单一元组:
a=(1,)
元组的运算与列表类似
元组的强制转换
tuple([1,2,3])
(1, 2, 3)
>>> tuple("sdff")
('s', 'd', 'f', 'f')
tuple((1,2,3))
(1, 2, 3)
函数:
len() 计算元组的元素个数
max() 返回元组中元素最大值
min() 返回元组中元素最小值
>>> len(filler)
4
>>> max(filler)
'd'
>>> min(filler)
'a'
tuple() 将列表转换为元组
>>> tuple("sdff")
('s', 'd', 'f', 'f')
>>> tuple((1,2,3))
(1, 2, 3)
收藏
举报
TAG:
Python
python