元祖(tuple):是对列表的一个二次加工,元素不可被修改不能被增加或删除,可以查看
(类)tuple:(元祖)
(对象)tu = (111,222,333)
(类)list:(列表)
(对象)tu = [111,222,333]
一般在写元祖,在最后一个参数加一个逗号v = (111,2222,333,)好区分
1、可以进行索引取值
2、可以进行切片取值
3、元祖的一级元素不可被修改不能被增加或删除
4、可以已进行for循环,可迭代对象(字符串,列表,元祖,三者可以相互转换)
5、书写格式加()
6、元祖也是有序的
7、
class tuple(object):
"""
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items
If the argument is a tuple, the return value is the same object.
"""
def count(self, value): # real signature unknown; restored from __doc__(统计里面某个数据在元祖出现的次数)
""" T.count(value) -> integer -- return number of occurrences of value """
return 0
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__(找到某个值在元祖的索引位置)
"""
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
"""
return 0
补充:创建不可修改的元素,就可以用元祖