Menu Close

Python tuple() Function

In this tutorial, we are going to learn all about the Python tuple function that is a part of python’s built-in functions. tuple() function in Python is used to convert an iterable into a tuple. Before going through this article, we will see a brief description of Python tuple.

What is Python Tuple?

In Python, Tuple is a collection of items that are ordered and unchangeable or immutable. Python tuple is written inside the circular bracket. Tuple in Python is also accepted, duplicate members.

Python tuple function?

Python tuple() is a built-in function in Python that is used to create a tuple().
In Python tuple() is an immutable sequence of type. which is not changeable if once created.

Syntax:

tuple(iterable)

Parameter:

tuple() function supports a parameter iterable (list, set, string, etc), Which are optional.

If the iterable not passed into the tuple() function then tuple() function return the empty tuple.

Python tuple() function example

Here we will go through some examples to understand the tuple function in Python.

Example:

t1 = tuple()
print('Tuple One:- ',t1)

t2 = tuple('Python')
print('Tuple Two:- ', t2)

t3 = tuple([1, 2, 3, 4, 5, 6, 7])
print('Tuple Three:- ',t3)

t4 = tuple({1: 'one', 2: 'two'})
print("Tuple four:- ", t4)

Output:

Tuple One:-  ()
Tuple Two:-  ('P', 'y', 't', 'h', 'o', 'n')
Tuple Three:-  (1, 2, 3, 4, 5, 6, 7)
Tuple four:-  (1, 2)

Conclusion

So, In this article, we have learned all about tuple function in Python along with examples. tuple function is the best python built-in function to convert any iterable into a tuple.

If you like this article, please share and keep visiting for further Python tutorials.

Python built-in functions

Fore more information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts