[Python] How to create a reference to a variable in python?

Discussão em 'Python' iniciado por Stack, Setembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    In the code:

    y = 7
    x = y
    x = 8


    y will be 7 and x will be 8. But I actually want changing x to change y at the same time. Can I assign the reference of y and do that?

    For example, in C++ the same thing can be achieved with:

    int y = 8;
    int &x = y;
    x = 9;


    Now, both y and x will be 9.

    Continue reading...

Compartilhe esta Página