[Python] How can I access the index value in a 'for' loop?

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    How do I access the index while iterating over a sequence with a for loop?

    xs = [8, 23, 45]

    for x in xs:
    print("item #{} = {}".format(index, x))


    Desired output:

    item #1 = 8
    item #2 = 23
    item #3 = 45

    Continue reading...

Compartilhe esta Página