What is a tuple in Python?

A tuple is an ordered collection of items written inside round brackets ( ). Unlike a list, a tuple is immutable, which means you cannot change, add or remove its items after it is created.

colors = ("red", "green", "blue")
print(colors[1])

colors[1] = "black"

Output:

Tutorials Class - Output Window

green
Traceback (most recent call last):
File "main.py", line 4, in <module>
colors[1] = "black"
TypeError: 'tuple' object does not support item assignment

Tuples are good for data that should not change, like a point (10, 20) or days of the week. A tuple with one item needs a comma, like ("apple",). See the Python Tuples chapter for more.


Learn more about the similar topics:
Tutorials
Python Lists
Python Tuples
Python Sets
Python Dictionary
Exercises & Assignments
Python program to find largest and smallest number in a list
Python program to remove duplicates from a list
Interview Questions & Answers
What is a list in Python?
What is a tuple in Python?
What is a set in Python?
What is a dictionary in Python?
What is a negative index in Python and why is it used?
What is the difference between a list and a tuple in Python?
What are mutable and immutable types in Python?