[Python] Print a list backwards

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have a code which i want to print this list backwards but it didn't work.

    It prints [2 , 4 , 6 , 8 , 10, 10]

    def printBackwards (list) :
    i = len(list)
    while (i > 0):
    list.append(list[i-1])
    i = i +1
    print(list)
    return

    myslist = [2 , 4 , 6 , 8 , 10]
    printBackwards(myslist)


    What i want is to print it [10 , 8 , 6 , 4 , 2] How can this be done ?

    EDIT: I want use my code not [::-1] or reverse() or something from other post WHICH I have seen . so its not duplicate . I dont want just work from what ever code however I want to edit my code to work. Thanks.

    Continue reading...

Compartilhe esta Página