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 |
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
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)
You can create an empty tuple using the tuple()
function.
empty_tuple = tuple()
print(empty_tuple)