python的数据对象——元组

元组spa

1.元组的特色索引

  • 不可更改
  • 元素是有序的

2.元组基本操做ast

  • 元组相加  >>> d+(2,3)
                           (1, '34', 23, 2, 3)
                           >>> d+(23,)
                           (1, '34', 23, 23)
                            >>> d+(3)
  • 错误代码>>> d+(3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: can only concatenate tuple (not "int") to tuple
    >>>
  • 检测元素是否存在>>> 3 in d
                               False
                               >>> if not 3 in d:
                               ...     print('missing fail')
                               ...
                               missing fail
                               >>>
     
  • 元组索引>>> d[0]
                  1
                 >>> d[:]
                 (1, '34', 23)

3.使用元组的缘由module

他的不可更改性
 call

相关文章
相关标签/搜索