Computer >> Computer tutorials >  >> Programming >> Python

Updating Tuples in Python


Tuples are immutable which means you cannot update or change the values of tuple elements. You are able to take portions of existing tuples to create new tuples as the following example demonstrates −

Example

#!/usr/bin/python
tup1 = (12, 34.56);
tup2 = ('abc', 'xyz');
# Following action is not valid for tuples
# tup1[0] = 100;
# So let's create a new tuple as follows
tup3 = tup1 + tup2;
print tup3;

Output

When the above code is executed, it produces the following result −

(12, 34.56, 'abc', 'xyz')