[Python] Why does my python for loop skip the last element in a list? [closed]

Discussão em 'Python' iniciado por Stack, Maio 2, 2025.

  1. Stack

    Stack Membro Participativo

    i'm trying to loop through all the elements in a list in python using a for loop. here's my code:

    my_list=[1,2,3,4,5]
    for i in range(len(my_list)-1):

    print(my_list)


    i have tried removing -1 gives the full output and looked into enumerate() but not sure how it applies here

    expected: 1 2 3 4 5 actual : 1 2 3 4

    Continue reading...

Compartilhe esta Página