The way you used the tuple was only to assign the single values to single variables in one line. This doesn't store the tuple anywhere, so you'll be left with 4 variables with 4 different values. When you change the value of country, you change the value of this single variable, not of the tuple, as string variables are "call by value" in python.
If you want to store a tuple you'd do it this way:
tup = ('Diana',32,'Canada','CompSci')
Then you can access the values via the index:
print tup[1] #32
Edit:
What I forgot to mention was that tuples are not mutable, so you can access the values, but you can't set them like you could with arrays.
You can still do :
name, age, country, job = tup
But the values will be copies of the tuple - so changing these wont change the tuple.
('Diana',32,'Canada','CompSci')
is unpacked to 4 differentstr
variables. Hence you can reassign the variablecountry
. However if you want to do something like('Diana',32,'Canada','CompSci')[2] = "India"
, you cannot as you are trying to change the value of theimmutable
tuple. – Sherilyntuple
only if i assign it to single variable? – Keelboat