[Python] How to change a global variable from a function in place? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    I want to change a variable from a function like this:

    def addone(x):
    #Some code
    inp = 5
    addone(inp)
    print(inp)
    #Prints 6


    I tried this:

    def addone(x):
    x += 1


    The variable only changes inside the function though, and the value outside did not change.

    Continue reading...

Compartilhe esta Página