[Python] Access data within tuples

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of tuples like so:

    tuples=[(41, 'Mike'), (29, 'Tom'), (28, 'Sarah'), (22, 'Jane'), (18, 'John']


    The ints are ages of the individuals and the strings are their names. The tuples are ordered by the individuals age on purpose.

    I understand list indexes work here. So if I want to access the first tuple then:

    tuples[0]


    will access

    (41, 'Mike')


    How do I access the values within the tuples?

    I would like to loop through the tuple and print: "They are" AGE "years old, and their name is" NAME.

    So for tuples[0] it would look like:

    "They are" 41 "years old, and their name is" Mike.

    Continue reading...

Compartilhe esta Página