[Python] Is the right-hand side of an assignment always evaluated before the assignment?

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    Here is a code snippet.

    x = {}
    x[1] = len(x)

    print x
    {1: 0}


    Is this well defined? That is, could x == {1: 1} instead?

    Because I remember that an equivalent program in C++ '98 (if we use std::map) has undefined behaviour. The output of the program was different when compiled with VS compiler and G++.

    Continue reading...

Compartilhe esta Página