Tuples

  • For the most part, we can just consider tuples to be immutable lists

  • Tuples are defined by ( )

  • The items of tuples are separated by commas

  • a neat trick we can do with tuples is unpacking

In [1]: atuple=('Python','2.0', ('was','released'), ['on','October','16th','2000'])

In [2]: atuple[3][3]
Out[2]: '2000'

In [3]: atuple[1]='3.0'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/net/rowley/ifs/data/bcc/duan/test_python/<ipython-input-3-6f783710c508> in <module>()
----> 1 atuple[1]='3.0'

TypeError: 'tuple' object does not support item assignment

Last updated

Massachusetts Institute of Technology