Python 元组(Tuple)随笔

Python Tuple:

  Tuple元组:元组是一个不可改变的序列集合

  Tuple定义:

tu = () 或 tu = tupe()        定义一个空元组

注:列表和元组可以自由转换,元组中函数列表中都存在对应的函数,

-----------------------------------------------------------

  Tuple 函数  

查看Tuple内置函数方式 :   dir(tuple)

 ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

count      ----统计元祖中指定元素或者对象个数

index      ----用于从列表中找出某个值第一个匹配项的索引位置(索引是以0为起始值开始计算)

猜你喜欢

转载自www.cnblogs.com/maruobo/p/9669262.html