w3resource logo


Python Exercises

Python Exercise: Colon of a tuple

Python tuple: Exercise-8 with Solution

Write a Python program to create the colon of a tuple.

Sample Solution :-

Python Code :

>>> from copy import deepcopy
>>> #create a tuple
>>> tuplex = ("HELLO", 5, [], True) 
>>> print(tuplex)
>>> #make a copy of a tuple using deepcopy() function
>>> tuplex_clone = deepcopy(tuplex)
>>> tuplex_clone[2].append(50)
>>> print(tuplex_clone)
>>> print(tuplex)
>>>

Output:

>>>
('HELLO', 5, [], True)
('HELLO', 5, [50], True)
('HELLO', 5, [], True)
>>>

Python Code Editor:

from copy import deepcopy
#create a tuple
tuplex = ("HELLO", 5, [], True)
print(tuplex)
#make a copy of a tuple using deepcopy() function
tuplex_clone = deepcopy(tuplex)
tuplex_clone[2].append(50)
print(tuplex_clone)
print(tuplex)

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.