Unpack a tuple into variables

EasyTuple Programs · 7 of 70

Write a Python program to assign the values of a tuple to several variables and print them.

Advertisement
Input
(6, 7, 3)
Output
a, 6
b, 7
c, 3

Approach

  1. Tuple unpacking: one name per item.

Solution

Python
a, b, c = (6, 7, 3)print("a,", a)print("b,", b)print("c,", c)
Output
a, 6
b, 7
c, 3

Line by line

Line 1

The number of names must match the number of items.

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs

1 thought on “Unpack a tuple into variables”

Leave a Comment