I stumbled upon a low-level Python problem that I cannot understand. I want to do something to a string inside a function and keep those alterations.
name = 'name'
def get_new_name(name):
name = 'new_name'
get_new_name(name)
print(name) # expected 'new_name', got 'name'
I would expect that I get new_name
printed, however, the result is name
.
I know I could get what I want by using return in the function, but can I somehow use a void-like function as described here to get what i want?