Take the following code
#module functions.py
def foo(input, new_val):input = new_val#module main.py
input = 5
functions.foo(input, 10)print input
I thought input would now be 10. Why is this not the case?
Take the following code
#module functions.py
def foo(input, new_val):input = new_val#module main.py
input = 5
functions.foo(input, 10)print input
I thought input would now be 10. Why is this not the case?
Everything is passed by value, but that value is a reference to the original object. If you modify the object, the changes are visible for the caller, but you can't reassign names. Moreover, many objects are immutable (ints, floats, strings, tuples).