How can I use Multiple-tuple in Python?

PythonProgramming

A multiple tuple is a tuple of tuples. 

example

((0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14))

You can iterate over a multiple tuple using the python destructuring syntax in the following way

x = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14))
for a, b, c in x:
print(a + b + c)

Output

This will give the output

3
12
21
30
39


This structure is useful when you want to return a structure that has defined order and you want it to be immutable.

raja
Published on 18-Apr-2018 14:36:48
Advertisements