r/learnpython • • Oct 26 '26

how do i overwrite a variable?

name = "Alice"

def func():
    name = "Bob"

func()

print(f"Hello, {name}!") # i want it to print bob
0 Upvotes

35 comments sorted by

View all comments

Show parent comment

1

u/nicodeemus7 Oct 26 '26

They could also just return the new name variable from the function and define the global variable name as the function