Skip to main content

tuple()

The tuple() function in Python is a built-in function that creates a tuple object. It can convert a sequence like a list or a string into a tuple. Tuples are immutable sequences, which means they cannot be modified after creation. This function is useful for converting other data structures into tuples for various operations in Python.

Parameter Values

Parameter Description
iterable

An optional parameter that can be any iterable object. It can be a list, a string, a dictionary, etc., whose elements will be used to create the tuple.

Return Values

The tuple() function in Python returns a tuple object, which can hold a mixture of any data types.

How to Use tuple() in Python

Example 1:

The tuple() function creates a tuple object. Tuples are immutable sequences, typically used to store collections of heterogeneous data.

data = tuple(['a', 'b', 'c'])
print(data)
Example 2:

You can create an empty tuple using the tuple() function.

empty_tuple = tuple()
print(empty_tuple)
Example 3:

The tuple() function can also convert other iterable objects like lists, strings, or sets into tuples.

string_tuple = tuple('hello')
print(string_tuple)