Skip to content
Related Articles

Related Articles

Improve Article

tuple() Function in Python

  • Difficulty Level : Easy
  • Last Updated : 23 Oct, 2020

The tuple() function is a built-in function in Python that can be used to create a tuple.

A tuple is an immutable sequence type.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course



Parameters: This function accepts a single parameter iterable (optional). It is an iterable(list, range etc..) or an iterator object. If an iterable is passed, the corresponding tuple is created. If the iterable is not passed, empty tuple is created .

Returns: It does not returns any-thing but creates a tuple.

Error and Exception: It returns a TypeError, if an iterable is not passed.

Below programs illustrate tuple() function in Python:
Program 1: Program demonstrating the use of tuple() function

# Python3 program demonstrating
# the use of tuple() function
# when parameter is not passed
tuple1 = tuple()
# when an iterable(e.g., list) is passed
list1= [ 1, 2, 3, 4
tuple2 = tuple(list1)
# when an iterable(e.g., dictionary) is passed
dict = { 1 : 'one', 2 : 'two'
tuple3 = tuple(dict)
# when an iterable(e.g., string) is passed
string = "geeksforgeeks" 
tuple4 = tuple(string)


(1, 2, 3, 4)
(1, 2)
('g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's')

Program 2: Program demonstrating the TypeError

# 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 :