w3resource

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:

Python Tuple: Create a tuple with numbers, and display a member.

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:

Flowchart: Create a tuple with numbers, and display a member

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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-3.php