Python tuple()

Python tuple() builtin function is used to create an object of type tuple.

Tuple is an immutable sequence of elements.

In this tutorial, we will learn about the syntax of Python tuple() function, and learn how to use this function with the help of examples.

Syntax

The syntax of tuple() function is

</>
Copy
tuple([iterable])

where

ParameterRequired/OptionalDescription
iterableOptionalA python iterable object whose elements will be used to create a Tuple.

Returns

The function returns tuple object.

Examples

In this example, we will create a tuple from an iterable, say a list.

Pass the list myList as argument to tuple() function. The function returns a tuple object with the elements of myList iterable object.

Python Program

</>
Copy
myList = [2, 0, 8, 6]
myTuple = tuple(myList)
print(myTuple)

Output

(2, 0, 8, 6)

Conclusion

In this Python Tutorial, we have learnt the syntax of Python tuple() builtin function, and also learned how to use this function, with the help of Python example programs.