[Python] Why assignment and sort of python list in one step doesn't work? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    The below code prints r as intended by sorting scores.

    scores=[1,2,4,2,4,7,1]
    scores.sort()
    r=scores
    print(r)


    However, the code prints r as null if I try doing the assignment in the same step as the sort. Can you help why that is the case?

    scores=[1,2,4,2,4,7,1]
    r=scores.sort()
    print(r)

    Continue reading...

Compartilhe esta Página