0

What is the usage of a tuple ?

18th Aug 2019, 7:11 AM
Scarlet
Scarlet - avatar
2 Answers
+ 5
Tuples can contain also different typs of objects like this: tup = (17, 4, 'af', [1,2,3], (4,14),{'red': [100,100,0]}) tuples are immutable which means that it is not possible to sssign new values to elements of a tuple or to add new elements or delete existing elements. if there is need to modify elements of a tuple it can be converted to list, apply the modifications and than concert back to tuple.
18th Aug 2019, 9:31 AM
Lothar
Lothar - avatar
+ 1
A tupel can contain multiple elements. E.g. if a python function should return two values, you can combine them in a tupel like 'return(a,b)'.
18th Aug 2019, 7:46 AM
Tom Hammerbacher
Tom Hammerbacher - avatar