+ 1
What does "tuples can be nested within each other" mean?
1 ответ
+ 2
A tuple is an object that contains an abitrary number of values.
E.g.
x = (1, 2, 3)
x is a tuple that has 3 numbers in it.
y = ('a', 'b', 'c')
y is a tuple that has 3 strings in it.
z = (1, 'b', 3)
z is a tuple that has both numbers and a string in it.
As you can see a tuple can contain any type of object in it. As a tuple itself is an object, a tuple can therefore contain another tuple.
e.g
x = (1, ('a', 'b'))
x is a tuple which has a number and another tuple in it.
This could have been alternatively written as the following but is equivalent to the example above:
my_tuple = ('a', 'b')
x = (1, my_tuple))
These are both an example of a nested tuple. Hope this helps.