Skip to content
Related Articles

Related Articles

tuple() Function in Python

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 03 Aug, 2022
View Discussion
Improve Article
Save Article

The Python tuple() function is a built-in function in Python that can be used to create a tuple. A tuple is an ordered and immutable sequence type.

Python tuple() Function Syntax

Syntax: tuple(iterable)

  • iterable (optional): It is an iterable(list, range etc..) or an iterator object
    •  If an iterable is passed, the corresponding tuple is created,
    • else, an empty tuple is created.

Return: Returns a Tuple

It raises a TypeError, if an iterable is not passed. Below programs illustrate tuple() function in Python.

Python tuple() Function Example:


l = [1,2,3]


(1, 2, 3)

Example 1: Uses of tuple() in Python

Program demonstrating the use of tuple() function.


# when parameter is not passed
tuple1 = tuple()
print("empty tuple:", tuple1)
# when an iterable(e.g., list) is passed
list1= [ 1, 2, 3, 4 ]
tuple2 = tuple(list1)
print("list to tuple:", tuple2)
# when an iterable(e.g., dictionary) is passed
dict = { 1 : 'one', 2 : 'two' }
tuple3 = tuple(dict)
print("dict to tuple:", tuple3)
# when an iterable(e.g., string) is passed
string = "geeksforgeeks";
tuple4 = tuple(string)
print("str to tuple:", tuple4)


empty tuple: ()
list to tuple: (1, 2, 3, 4)
dict to tuple: (1, 2)
str to tuple: ('g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's')

Example 2: Errors when using Tuple

Program demonstrating the TypeError using tuple()


# Python3 program demonstrating
# the TypeError in tuple() function
# Error when a non-iterable is passed
tuple1 = tuple(1)


Traceback (most recent call last):
  File "/home/", line 5, in 
TypeError: 'int' object is not iterable

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!