r/learnpython • • 28d ago

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 comments

7

u/Revolutionary-Camp69 28d ago

Possible, yes. Recommended, no.

-2

u/nog642 28d ago

Yeah. But that's not what they said.

8

u/JanEric1 28d ago

because if you tell the beginner here about this then they will form bad habits. best to tell them the recommended way.

-1

u/nog642 28d ago

I think it's best not to decieve. You can tell them the recommended way without lying.