[Python] Why do these two lists become the same (python)?

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    Python query. why does req1 end up being the same as req2? How do I preserve req1 with 3 original values? I would have thought req1 would still be [23,24,25] the following code displays [[23, 24, 25, 26], [23, 24, 25, 26]] ``

    req1 = [23,24,25]
    req2 = req1
    req2.append(26)
    op = [[],[]]
    op[0] = req2
    op[1] = req1
    print(op)


    ``

    Continue reading...

Compartilhe esta Página