Python Exercise: Create a tuple with numbers, and display a member
Python tuple: Exercise-3 with Solution
Write a Python program to create a tuple of numbers and print one item.
Visual Presentation:
Sample Solution:
Python Code:
# Create a tuple containing a sequence of numbers
tuplex = 5, 10, 15, 20, 25
# Print the contents of the 'tuplex' tuple
print(tuplex)
# Create a tuple with a single item (note the comma after the item)
tuplex = 5,
# Print the contents of the 'tuplex' tuple
print(tuplex)
Sample Output:
(5, 10, 15, 20, 25) (5,)
Flowchart:
Python Code Editor:
Previous: Write a Python program to create a tuple with different data types.
Next: Write a Python program to unpack a tuple in several variables.
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://w3resource.com/python-exercises/tuple/python-tuple-exercise-3.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics