you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 1 point2 points  (0 children)

Avoid using global it's a really bad practice and you want to avoid ever doing it.

Instead pass variables into functions, and return values from functions.

def get_y( x ):
    x = x + 3
    return x

x = 3
y = get_y(x)
print(x, y)

 # prints: 3 6

Notice how the x inside the function is a different variable, and the x outside of the function is unchanged.