python tuple 操作

时间:2023-03-10 05:56:34
python tuple 操作

特点:不可改(与字符串一样。不允许删除和修改)

操作:
1、print 可使用跟%的元祖  print( '%s is %d years old' % (name, age))

2、像列表一样有索引

3、定义一个元素,(1,),(1)算是int数

4、tuple 里的list可修改(tuple的每个元素,指向永远不变)

八、元组内置函数
Python元组包含了以下内置函数
1、cmp(tuple1, tuple2):比较两个元组元素。
2、len(tuple):计算元组元素个数。
3、max(tuple):返回元组中元素最大值。
4、min(tuple):返回元组中元素最小值。
5、tuple(seq):将列表转换为元组。

没有append(),insert()这样的方法