Python Exercise: Create a tuple with numbers, and display a member
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics