元祖(tuple)的帮助文档

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.
 |
 |  Methods defined here:
 |
 |  __add__(self, value, /)
 |      Return self+value.
 |
 |  __contains__(self, key, /)
 |      Return key in self.
 |
 |  __eq__(self, value, /)
 |      Return self==value.
 |
 |  __ge__(self, value, /)
 |      Return self>=value.
 |
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |
 |  __getitem__(self, key, /)
 |      Return self[key].
 |
 |  __getnewargs__(...)
 |
 |  __gt__(self, value, /)
 |      Return self>value.
 |
 |  __hash__(self, /)
 |      Return hash(self).
 |
 |  __iter__(self, /)
 |      Implement iter(self).
 |
 |  __le__(self, value, /)
 |      Return self<=value.
 |
 |  __len__(self, /)
 |      Return len(self).
 |
 |  __lt__(self, value, /)
 |      Return self integer -- return number of occurrences of value
 |
 |  index(...)  #查找元素下标
 |      T.index(value, [start, [stop]]) -> integer -- return first index of value.
 |      Raises ValueError if the value is not present.

其实tuple只有两个方法,count和index

>>> a
(1, 2, 3)
>>> a.count()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: count() takes exactly one argument (0 given)
>>> a.count(1)
1
>>> a = (1,1,1,2,3,4,5)
>>> a
(1, 1, 1, 2, 3, 4, 5)
>>> a.count(1)
3
>>> a.index(1)
0
>>> a.index(2)
3

你可能感兴趣的:(元祖(tuple)的帮助文档)