python

How to Convert a List into a Tuple in Python

In this tutorial, we are going to see how to convert List into a Tuple in Python. Python provides different types of variables for programmers. We can use data types like int, float, string, list, set… in our applications. When using different types of variables, it may be necessary to convert these to different types.
 

 

How to Convert a List into a Tuple in Python
# List of integers 
nbr_liste = [1, 2, 3, 4, 5, 6]
print(nbr_liste)
# Convert list to tuple
nbr_tuple = tuple(nbr_liste)
# Print the tuple
print(nbr_tuple)

Output:

[1, 2, 3, 4, 5, 6]
(1, 2, 3, 4, 5, 6)
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *