0
What is the usage of a tuple ?
2 Antworten
+ 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.
+ 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)'.