How To Convert A List To Tuple In Python

How to convert a list to tuple in python
Table of Contents

Want to know how to convert a list to a tuple in python then today I will show you how to convert a list to a tuple in python programming language.

Converting a list to a tuple is going to be very easy and simple to do. Below is the example that we want to achieve

				
					Input : [1, 2, 3, 4]
Output : (1, 2, 3, 4)
				
			

There are 3 ways that we can use to convert a list to a tuple in python we will see each step by step.

1. Converting a list to a tuple using “tuple(listname)”

The first method of typecasting from a list to a tuple is very easy we just have to use the builtin python method like this

				
					list = [1,2,3,4,5]
tup = tuple(list)

print(tup)
				
			

Output:

				
					(1,2,3,4,5)
				
			

2. Converting a list to a tuple using a loop

The second method for converting a list to a tuple using for loop inside tuple you can see from the below code.

				
					list = [1,2,3,4,5]
tup = tuple(i for i in list)

print(tup)
				
			

Output:

				
					(1,2,3,4,5)
				
			

3. Converting a list to a tuple using “(*list, )”

This is another method that you can use to convert a list to a tuple using (*list,) this is also very simple and easy to do you can see the code below.

				
					list = [1,2,3,4,5]
tup = (*list, )

print(tup)
				
			

Output:

				
					(1,2,3,4,5)
				
			

These were all the 3 methods to convert a list to a tuple in python you can use any of the methods you find easy I found the first one very simple and easy to do.

If you want a video guide on how to convert a list to tuple in python then you can watch this youtube video.

Here are some more guides you can read:

I hope you found what you were looking for and found this guide helpful if you want more guides like this you:

Thank you for reading, Have a nice day 🙂

Share This Post
Share on facebook
Share on twitter
Share on email
Share on whatsapp

Leave a Reply

Subscribe To Our Newsletter

Get updates and learn from the best

Latest Guides & Articles