Python utility belt: unpacking tuples

Leonardo Furtado - Jan 7 '21 - - Dev Community

Hi devs,
hi

Today I would like to show you something interesting that you can use. Take a look at this code:

things = [('teen', '10'), ('twenty', '20')]
Enter fullscreen mode Exit fullscreen mode

How do you print this? You've probably already thought of some ways to do this and now I'm going to show you some::

for index, (word, number) in enumerate(numbers):
    print(index, word, number)
Enter fullscreen mode Exit fullscreen mode

When you run this code, you'll receive it:

0 teen 10
1 twenty 20
Enter fullscreen mode Exit fullscreen mode

It is simple and useful, is it?
easy
Hope you enjoy it, have a great day and an AWESOME year.

. . . . . .