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.
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
() (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
Traceback (most recent call last): File "/home/eaf759787ade3942e8b9b436d6c60ab3.py", line 5, in tuple1=tuple(1) TypeError: 'int' object is not iterable
- Unpacking a Tuple in Python
- Python | Reversing a Tuple
- Python | Find whether all tuple have same length
- Python | Convert a list into a tuple
- Python | Removing strings from tuple
- Python | Split tuple into groups of n
- Python | Unpacking tuple of lists
- Python | Summation of list as tuple attribute
- Python | Reverse each tuple in a list of tuples
- Python | Grouped summation of tuple list
- Python | Modifying tuple contents with list
- Python | Program to convert a tuple to a string
- Python | Dictionary to list of tuple conversion
- Python | Count occurrences of an element in a Tuple
- Python | Get first index values in tuple of strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai