A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogeneous and immutable.
Creating a Tuple
A tuple is created by placing all the items inside parentheses (), separated by commas. A tuple can have any number of items and they can be of different data types.
Example:
Python
# Creating an empty Tuple
tup = ()
print(tup)
# Using String
tup = ('Geeks', 'For')
print(tup)
# Using List
li = [1, 2, 4, 5, 6]
print(tuple(li))
# Using Built-in Function
tup = tuple('Geeks')
print(tup)
Output()
('Geeks', 'For')
(1, 2, 4, 5, 6)
('G', 'e', 'e', 'k', 's')
Let’s understand tuple in detail:
Creating a Tuple with Mixed Datatypes.
Tuples can contain elements of various data types, including other tuples, lists, dictionaries and even functions.
Example:
Python
# Creating a Tuple with Mixed Datatype
tup = (5, 'Welcome', 7, 'Geeks')
print(tup)
# Creating a Tuple with nested tuples
tup1 = (0, 1, 2, 3)
tup2 = ('python', 'geek')
tup3 = (tup1, tup2)
print(tup3)
# Creating a Tuple with repetition
tup1 = ('Geeks',) * 3
print(tup1)
# Creating a Tuple with the use of loop
tup = ('Geeks')
n = 5
for i in range(int(n)):
tup = (tup,)
print(tup)
Output(5, 'Welcome', 7, 'Geeks')
((0, 1, 2, 3), ('python', 'geek'))
('Geeks', 'Geeks', 'Geeks')
('Geeks',)
(('Geeks',),)
((('Geeks',),),)
(((('Geeks',),),),)
((((('Geeks',),),),),)
Python Tuple Operations
Below are the Python tuple operations.
- Accessing of Python Tuples
- Concatenation of Tuples
- Slicing of Tuple
- Deleting a Tuple
Accessing of Tuples
We can access the elements of a tuple by using indexing and slicing, similar to how we access elements in a list. Indexing starts at 0 for the first element and goes up to n-1, where n is the number of elements in the tuple. Negative indexing starts from -1 for the last element and goes backward.
Example:
Python
# Accessing Tuple with Indexing
tup = tuple("Geeks")
print(tup[0])
# Accessing a range of elements using slicing
print(tup[1:4])
print(tup[:3])
# Tuple unpacking
tup = ("Geeks", "For", "Geeks")
# This line unpack values of Tuple1
a, b, c = tup
print(a)
print(b)
print(c)
OutputG
('e', 'e', 'k')
('G', 'e', 'e')
Geeks
For
Geeks
Concatenation of Tuples
Tuples can be concatenated using the + operator. This operation combines two or more tuples to create a new tuple.
Note- Only the same datatypes can be combined with concatenation, an error arises if a list and a tuple are combined.

Python
tup1 = (0, 1, 2, 3)
tup2 = ('Geeks', 'For', 'Geeks')
tup3 = tup1 + tup2
print(tup3)
Output(0, 1, 2, 3, 'Geeks', 'For', 'Geeks')
Slicing of Tuple
Slicing a tuple means creating a new tuple from a subset of elements of the original tuple. The slicing syntax is tuple[start:stop:step].
Note- Negative Increment values can also be used to reverse the sequence of Tuples.

Python
# Slicing of a Tuple with Numbers
tup = tuple('GEEKSFORGEEKS')
# Removing First element
print(tup[1:])
# Reversing the Tuple
print(tup[::-1])
# Printing elements of a Range
print(tup[4:9])
Output('E', 'E', 'K', 'S', 'F', 'O', 'R', 'G', 'E', 'E', 'K', 'S')
('S', 'K', 'E', 'E', 'G', 'R', 'O', 'F', 'S', 'K', 'E', 'E', 'G')
('S', 'F', 'O', 'R', 'G')
Deleting a Tuple
Since tuples are immutable, we cannot delete individual elements of a tuple. However, we can delete an entire tuple using del statement.
Note- Printing of Tuple after deletion results in an Error.
Python
# Deleting a Tuple
tup = (0, 1, 2, 3, 4)
del tup
print(tup)
Tuple Built-In Methods
Tuples support only a few methods due to their immutable nature. The two most commonly used methods are count() and index()
| Built-in-Method | Description |
|---|
| index( ) | Find in the tuple and returns the index of the given value where it’s available |
| count( ) | Returns the frequency of occurrence of a specified value |
Tuple Built-In Functions
| Built-in Function | Description |
|---|
| all() | Returns true if all element are true or if tuple is empty |
|---|
| any() | return true if any element of the tuple is true. if tuple is empty, return false |
|---|
| len() | Returns length of the tuple or size of the tuple |
|---|
| enumerate() | Returns enumerate object of tuple |
|---|
| max() | return maximum element of given tuple |
|---|
| min() | return minimum element of given tuple |
|---|
| sum() | Sums up the numbers in the tuple |
|---|
| sorted() | input elements in the tuple and return a new sorted list |
|---|
| tuple() | Convert an iterable to a tuple. |
|---|
Tuples VS Lists
| Similarities | Differences |
|---|
Functions that can be used for both lists and tuples:
len(), max(), min(), sum(), any(), all(), sorted()
| Methods that cannot be used for tuples:
append(), insert(), remove(), pop(), clear(), sort(), reverse()
|
Methods that can be used for both lists and tuples:
count(), Index()
| we generally use ‘tuples’ for heterogeneous (different) data types and ‘lists’ for homogeneous (similar) data types. |
| Tuples can be stored in lists. | Iterating through a ‘tuple’ is faster than in a ‘list’. |
| Lists can be stored in tuples. | ‘Lists’ are mutable whereas ‘tuples’ are immutable. |
| Both ‘tuples’ and ‘lists’ can be nested. | Tuples that contain immutable elements can be used as a key for a dictionary. |
Tuples Programs
Useful Links:
Python Tuples – FAQs
What are the Characteristics of Tuples in Python?
Characteristics of Tuples:
- Immutable: Once created, the elements of a tuple cannot be modified, added or removed.
- Ordered: Tuples maintain the order of elements and elements can be accessed using indices.
- Allow Duplicate Elements: Tuples can contain duplicate values and preserve the position of elements.
- Can Contain Mixed Data Types: Tuples can hold different data types, such as integers, strings and lists.
- Hashable: If all elements of a tuple are hashable, the tuple itself can be used as a dictionary key or set element.
- Faster than Lists: Due to their immutability, tuples are generally faster for iteration and access operations compared to lists.
How to Create and Use Tuples in Python?
Creating Tuples:
- Use parentheses
() to create a tuple and separate elements with commas. - Tuples can also be created without parentheses.
Examples:
# Creating tuples
tuple1 = (1, 2, 3, 4)
tuple2 = (1, "hello", 3.14)
tuple3 = (1,) # A tuple with one element (note the comma)
# Tuple without parentheses
tuple4 = 1, 2, 3, 4
# Accessing elements
print(tuple1[0]) # Output: 1
print(tuple2[1]) # Output: hello
# Slicing
print(tuple1[1:3]) # Output: (2, 3)
Are Tuples Mutable in Python?
No, tuples are immutable. This means that once a tuple is created, its elements cannot be changed, added or removed. Attempting to modify a tuple will result in a TypeError.
Example:
tuple1 = (1, 2, 3)
# Attempt to modify an element
try:
tuple1[1] = 4
except TypeError as e:
print(e) # Output: 'tuple' object does not support item assignment
How to Unpack Elements from a Tuple in Python?
Tuple unpacking allows us to assign elements of a tuple to multiple variables in a single statement.
Examples:
# Unpacking a tuple
person = ("Alice", 30, "Engineer")
name, age, profession = person
print(name) # Output: Alice
print(age) # Output: 30
print(profession) # Output: Engineer
# Unpacking with a placeholder
a, *b, c = (1, 2, 3, 4, 5)
print(a) # Output: 1
print(b) # Output: [2, 3, 4]
print(c) # Output: 5
When Should Tuples be Used Over Lists in Python?
Tuples should be used over lists in the following scenarios:
- Immutability: When we need a fixed collection of items that should not be modified.
- Hashable Collections: When we need to use a composite key in a dictionary or an element in a set and the tuple’s elements are hashable.
- Performance: When we require a more memory-efficient and faster alternative to lists for iteration and access.
- Data Integrity: When we want to ensure that a collection of values remains unchanged throughout the program.
Examples of Tuple Use Cases:
- Representing fixed records: Coordinates, RGB color values, database rows.
- Function return values: Functions that return multiple values can use tuples.
- Using as dictionary keys: Tuples can be used as keys in dictionaries.
Suggested Quiz
10 Questions
How to create an empty tuple in Python?
Explanation:
Both () and tuple() create an empty tuple in Python.
What is the output of (1, 2, 3) + (4, 5, 6)?
Explanation:
The + operator concatenates tuples.
How can you access the second element of the tuple t = (1, 2, 3)?
Explanation:
Tuple indices start from 0, so t[1] refers to the second element.
What is the output of ('repeat',) * 3?
-
('repeat', 'repeat', 'repeat')
-
-
-
Explanation:
Multiplying a tuple repeats its content.
Which of the following is true for the tuple t = (1, 2, [3, 4])?
-
Tuples cannot contain mutable objects like lists.
-
t[2][0] = 5 is a valid operation.
-
-
Tuples can only contain integers.
Explanation:
While tuples themselves are immutable, they can contain mutable objects like lists.
What happens if we try to assign a value to an element in a tuple?
-
-
-
-
The tuple is converted to a list.
Explanation:
Tuples are immutable, so attempting to change an element raises a TypeError.
Which of the following methods is not available for tuples?
Explanation:
Tuples cannot be sorted in-place because they are immutable; hence no .sort() method.
Which of the following is a correct statement about tuple unpacking?
-
x, y, z = (1, 2, 3) is an invalid statement.
-
Tuple unpacking requires more variables than the elements in the tuple.
-
Tuple unpacking can be done without matching the exact number of elements
-
x, y, z = (1, 2, 3) unpacks the values into x, y, and z
Explanation:
Tuple unpacking assigns each element of a tuple to a variable provided they match in quantity.
What is the output of tuple(map(lambda x: x*x, [1, 2, 3]))?
Explanation:
The map() function applies a function to every item of an iterable and tuple() converts the result to a tuple.
What does the following tuple comprehension do? tuple(x for x in range(5))
-
Creates a tuple with elements 0 to 4.
-
-
Creates a list instead of a tuple.
-
Explanation:
This is a generator expression passed to the tuple() constructor, which creates a tuple containing numbers from 0 to 4.
Quiz Completed Successfully
Your Score : 2/10
Accuracy : 0%
Login to View Explanation
1/10
1/10
< Previous
Next >
Similar Reads
Python Tuples
A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene
7 min read
Tuples in Python
Python Tuple is a collection of objects separated by commas. A tuple is similar to a Python list in terms of indexing, nested objects, and repetition but the main difference between both is Python tuple is immutable, unlike the Python list which is mutable. [GFGTABS] Python # Note : In case of list,
6 min read
Create a List of Tuples in Python
List of tuple is used to store multiple tuples together into List. We can create a list that contains tuples as elements. This practice is useful for memory efficiency and data security as tuples are immutable. The simplest way to create a list of tuples is to define it manually by specifying the va
4 min read
Create a tuple from string and list - Python
Sometimes, we can have a problem in which we need to construct a new container with elements from different containers. This kind of problem can occur in domains in which we use different types of data. Let's discuss ways to convert string and list data to tuple. Create a tuple from string and list
5 min read
Access front and rear element of Python tuple
Sometimes, while working with records, we can have a problem in which we need to access the initial and last data of a particular record. This kind of problem can have application in many domains. Let's discuss some ways in which this problem can be solved. Method #1: Using Access Brackets We can pe
6 min read
Python - Element Index in Range Tuples
Sometimes, while working with Python data, we can have a problem in which we need to find the element position in continuous equi ranged tuples in list. This problem has applications in many domains including day-day programming and competitive programming. Let's discuss certain ways in which this t
6 min read
Unpacking a Tuple in Python
Python Tuples In python tuples are used to store immutable objects. Python Tuples are very similar to lists except to some situations. Python tuples are immutable means that they can not be modified in whole program. Packing and Unpacking a Tuple: In Python, there is a very powerful tuple assignment
3 min read
Python | Unpacking nested tuples
Sometimes, while working with Python list of tuples, we can have a problem in which we require to unpack the packed tuples. This can have a possible application in web development. Let's discuss certain ways in which this task can be performed. Method #1 : Using list comprehension This task can be p
6 min read
Python | Slice String from Tuple ranges
Sometimes, while working with data, we can have a problem in which we need to perform the removal from strings depending on specified substring ranges. Let's discuss certain ways in which this task can be performed. Method #1: Using loop + list slicing: This is the brute force task to perform this t
3 min read
Python - Clearing a tuple
Sometimes, while working with Records data, we can have a problem in which we may require to perform clearing of data records. Tuples, being immutable cannot be modified and hence makes this job tough. Let's discuss certain ways in which this task can be performed. Method #1 : Using list() + clear()
4 min read
Python program to remove last element from Tuple
Given a tuple, the task is to write a Python program to delete the last element in the tuple in Python. Example: Input: ("geeks", "for", "geeks") Output:("geeks", "for") Explanation: Here we are deleting the last element of the tuple and finally modifying the original one. Note: Tuples are immutable
3 min read
Python | Removing duplicates from tuple
Many times, while working with Python tuples, we can have a problem removing duplicates. This is a very common problem and can occur in any form of programming setup, be it regular programming or web development. Let's discuss certain ways in which this task can be performed. Method #1 : Using set()
4 min read
Python - AND operation between Tuples
Sometimes, while working with records, we might have a common problem of performing AND operation contents of one tuple with corresponding index of other tuple. This has application in almost all the domains in which we work with tuple records especially Data Science. Let’s discuss certain ways in w
4 min read
Python - Sum of tuple elements
Sometimes, while programming, we have a problem in which we might need to perform summation among tuple elements. This is an essential utility as we come across summation operations many times and tuples are immutable and hence required to be dealt with. Let’s discuss certain ways in which this task
6 min read
Python | Ways to concatenate tuples
Many times, while working with records, we can have a problem in which we need to add two records and store them together. This requires concatenation. As tuples are immutable, this task becomes little complex. Let's discuss certain ways in which this task can be performed. Method #1 : Using + opera
6 min read
Python | Repeating tuples N times
Sometimes, while working with data, we might have a problem in which we need to replicate, i.e construct duplicates of tuples. This is an important application in many domains of computer programming. Let's discuss certain ways in which this task can be performed. Method #1 : Using * operator The mu
5 min read
Python Membership and Identity Operators
There is a large set of Python operators that can be used on different datatypes. Sometimes we need to know if a value belongs to a particular set. This can be done by using the Membership and Identity Operators. In this article, we will learn about Python Membership and Identity Operators. Table of
5 min read
Python | Compare tuples
Sometimes, while working with records, we can have a problem in which we need to check if each element of one tuple is greater/smaller than it's corresponding index in other tuple. This can have many possible applications. Let's discuss certain ways in which this task can be performed. Method #1 : U
4 min read
How to Join a list of tuples into one list?
In Python, we may sometime need to convert a list of tuples into a single list containing all elements. Which can be done by several methods. The simplest way to join a list of tuples into one list is by using nested for loop to iterate over each tuple and then each element within that tuple. Let's
2 min read
Python - Join Tuples if similar initial element
Sometimes, while working with Python tuples, we can have a problem in which we need to perform concatenation of records from the similarity of initial element. This problem can have applications in data domains such as Data Science. Let's discuss certain ways in which this task can be performed. Inp
8 min read
Python - Create list of tuples using for loop
In this article, we will discuss how to create a List of Tuples using for loop in Python. Let's suppose we have a list and we want a create a list of tuples from that list where every element of the tuple will contain the list element and its corresponding index. Method 1: Using For loop with append
2 min read
How to iterate through list of tuples in Python
In Python, a list of tuples is a common data structure used to store paired or grouped data. Iterating through this type of list involves accessing each tuple one by one and sometimes the elements within the tuple. Python provides several efficient and versatile ways to do this. Let’s explore these
2 min read
Python Tuple Methods
Python Tuples is an immutable collection of that are more like lists. Python Provides a couple of methods to work with tuples. In this article, we will discuss these two methods in detail with the help of some examples. Count() MethodThe count() method of Tuple returns the number of times the given
3 min read
Python Tuple Exercise
Basic Tuple ProgramsPython program to Find the size of a TuplePython – Maximum and Minimum K elements in TupleCreate a list of tuples from given list having number and its cube in each tuplePython – Adding Tuple to List and vice – versaPython – Sum of tuple elementsPython – Modulo of tuple elementsP
3 min read