Python tutorial- Tuple


As you already knew, tuple cannot be modified that is contrast to the list. Sometimes, you don’t want anyone to change the items of the sequences. In this case, using tuples is a good choice. If you try to modify the list such as deleting an item, or inserting a new item, an error will be raised.
>>> tu=(1,2,3)

>>> tu
(1, 2, 3)
>>> tu[0]
>>> tu[0]=4
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

Note: you can access the elements of the tuple in the same ways as you did with the list.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.