自学Python2.3-基本数据类型-元组tuple(object) 方法

Python tuple方法总结

一、元组的简介

1.元组与列表一样,也是一种序列,但是唯一不同的元组是不能修改的

2.元组的元素不可修改,但是元组元素的元素是可以修改的

3.元组通过()括起来表示   (1,2,3)

4.元组可以使用没有包含内容的(),表示空

二、 元组的方法

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 def __add__(self, *args, **kwargs): # real signature unknown
""" Return self+value. """
pass def __contains__(self, *args, **kwargs): # real signature unknown
""" Return key in self. """
pass def __eq__(self, *args, **kwargs): # real signature unknown
""" Return self==value. """
pass def __getattribute__(self, *args, **kwargs): # real signature unknown
""" Return getattr(self, name). """
pass def __getitem__(self, *args, **kwargs): # real signature unknown
""" Return self[key]. """
pass def __getnewargs__(self, *args, **kwargs): # real signature unknown
pass def __ge__(self, *args, **kwargs): # real signature unknown
""" Return self>=value. """
pass def __gt__(self, *args, **kwargs): # real signature unknown
""" Return self>value. """
pass def __hash__(self, *args, **kwargs): # real signature unknown
""" Return hash(self). """
pass def __init__(self, seq=()): # known special case of tuple.__init__
"""
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items If the argument is a tuple, the return value is the same object.
# (copied from class doc)
"""
pass def __iter__(self, *args, **kwargs): # real signature unknown
""" Implement iter(self). """
pass def __len__(self, *args, **kwargs): # real signature unknown
""" Return len(self). """
pass def __le__(self, *args, **kwargs): # real signature unknown
""" Return self<=value. """
pass def __lt__(self, *args, **kwargs): # real signature unknown
""" Return self<value. """
pass def __mul__(self, *args, **kwargs): # real signature unknown
""" Return self*value.n """
pass @staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass def __ne__(self, *args, **kwargs): # real signature unknown
""" Return self!=value. """
pass def __repr__(self, *args, **kwargs): # real signature unknown
""" Return repr(self). """
pass def __rmul__(self, *args, **kwargs): # real signature unknown
""" Return self*value. """
pass

tuple源码

1.count(self, value),返回对象value在列表中出现的次数

tuple1=(1,2,3,4,5,6,3,8,444,3,)
result=tuple1.count(3)
print(result)

输出3

2.  index(self, value, start=None, stop=None),返回列表中匹配对象value的第一个列表项的索引,无匹配元素时产生异常

tuple1=(1,2,3,4,5,6,3,8,444,3,)
result=tuple1.index(3)
print(result)

输出2  

tuple1=(1,2,3,4,5,6,3,8,444,3,)
tuple1.append(99)
print(tuple1)

输出报错

自学Python2.3-基本数据类型-元组tuple(object) 方法

上一篇:[PyCharm] 设置自动启动时自动打开项目


下一篇:QT信号与槽