Python Exercise: Convert a list to a tuple
Python tuple: Exercise-11 with Solution
Write a Python program to convert a list to a tuple.
Visual Presentation:
Sample Solution:
Python Code:
# Create a list containing a sequence of numbers
listx = [5, 10, 7, 4, 15, 3]
# Print the contents of the 'listx' list
print(listx)
# Use the 'tuple()' function, a built-in Python function, to convert the 'listx' list to a tuple
tuplex = tuple(listx)
# Print the contents of the 'tuplex' tuple
print(tuplex)
Sample Output:
[5, 10, 7, 4, 15, 3] (5, 10, 7, 4, 15, 3)
Flowchart:
Python Code Editor:
Previous: Write a Python program to check whether an element exists within a tuple.
Next: Write a Python program to remove an item from a tuple.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/tuple/python-tuple-exercise-11.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics