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

3

u/backfire10z Oct 26 '26

It being a part of the language and it being recommended to use in trivial situations like this are two different things. Python can do a lot of things, doesn’t mean you should be doing all of them regularly.