标签:python
元组
>>> a = () #创建空元组
>>> print(a)
()
>>> b = (1,)
>>> print(b)
(1,)
>>> c = (1, 2, 4, 9, 20, 99) #创建元组
>>> d = (199, 888)
>>> e = (c + d) #元组拼接
>>> e
(1, 2, 4, 9, 20, 99, 199, 888)
>>> len(e) #计算元组元素个数
8
>>> max(e) #返回元组中元素最大值
888
>>> min(e) #返回元组中元素最小值
1
>>> e[2] #元组索引
4
>>> e[-2]
199
>>> e[1:] #元组截取
(2, 4, 9, 20, 99, 199, 888)
>>> f = [‘tianshi‘,‘buding‘,‘chun‘,‘xia‘]
>>> g = tuple(f) #将列表转换为元组
>>> g
(‘tianshi‘, ‘buding‘, ‘chun‘, ‘xia‘)
>>> del g #删除元组
>>> g
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
g
NameError: name ‘g‘ is not defined
本文出自 “每天进步一点点” 博客,请务必保留此出处http://zuoshou.blog.51cto.com/2579903/1978088
标签:python
原文地址:http://zuoshou.blog.51cto.com/2579903/1978088