- Home
- /
- Python Tuples
Python Tutorial
Introduction
Python Data Types & Oper...
Python Strings
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Conditional Statements
Python Loops
Python Functions
Python Modules
Python OOPS
Advanced Topics
File Handling
- Home
- /
- Python Tuples
Python Tuples
A tuple is just like a list — it can store multiple items in a single variable, but with one key difference: tuples cannot be changed once created. That means you can’t add, remove, or update items after the tuple is defined.
What is a Tuple?
Tuples are ordered — the order in which you define the items is preserved.
Tuple elements are separated by commas
,
.Tuples are written inside round brackets
()
instead of square brackets[]
.Tuples are immutable (unchangeable after creation).
Example 1 – Numbers and Colors in Tuples
numbers = (10, 20, 20, 30, 50, 40, 60)
colors = ("Red", "Green", "Blue")
print(numbers)
print(colors)
Output:
(10, 20, 20, 30, 50, 40, 60)
('Red', 'Green', 'Blue')
As you can see, tuples can hold duplicate items too, just like lists.
Example 2 – Mixed Data Types in a Tuple
Tuples can also store different types of values — strings, numbers, floats — all together.
profile = ("Arshyan", 21, "Software Engineer", 9.2)
print(profile)
Output:
('Arshyan', 21, 'Software Engineer', 9.2)
This flexibility makes tuples great for storing related but different pieces of information.
Key Takeaway:
If you need a container where the data shouldn’t be changed, use a tuple instead of a list. They’re safe, fast, and very memory-efficient.
Keep learning, keep practicing — only on Learn With Arshyan!