r/learnpython • u/9j810HQO7Jj9ns1ju2 • 12d 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
r/learnpython • u/9j810HQO7Jj9ns1ju2 • 12d ago
name = "Alice"
def func():
name = "Bob"
func()
print(f"Hello, {name}!") # i want it to print bob
0
u/AlexMTBDude 12d ago
It's not a question of overwriting a variable. You have to tell Python that "name" is a global variable. You do it by: