How can I use Multiple-tuple in Python?


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.

Updated on: 05-Mar-2020

902 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements