Updating tuples

Tuple updating is not possible in Python, as tuples are immutable. But you can create a new tuple with an existing tuple, as shown in the following example:

#!/usr/bin/python3
cities = ('Mumbai', 'Bangalore', 'Chennai', 'Pune')
numbers = (1,2,3,4,5,6,7)
tuple1 = cities + numbers
print(tuple1)

Output:
('Mumbai', 'Bangalore', 'Chennai', 'Pune', 1, 2, 3, 4, 5, 6, 7)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset