python tuple

来源:互联网 发布:熊猫采集软件体验 编辑:程序博客网 时间:2024/06/06 18:16

python-tuple

简介

  • tuple是一个有序的集合
  • tuple和list很类似,但是tuple中元素不可更改

tuple操作

In [1]: myTuple = (2,True,4,96)In [2]: myTupleOut[2]: (2, True, 4, 96)In [3]: len(myTuple)Out[3]: 4In [4]: myTuple*3Out[4]: (2, True, 4, 96, 2, True, 4, 96, 2, True, 4, 96)In [5]: myTuple[0:2]Out[5]: (2, True)In [6]: myTuple[1] = False---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-6-eb935a311b80> in <module>()----> 1 myTuple[1] = FalseTypeError: 'tuple' object does not support item assignment
0 0
原创粉丝点击