3 ms·
Unless of course the value you pass is an object. In which case it will change in the scope you called the function from.
by bfw 16y ago
Unless of course the value you pass is an object. In which case it will change in the scope you called the function from.
- driax 16y agoThe point is that you can't pass an object. The object lives on the heap and you always pass references around. Thats why when we pass in a list we can change the contents. The passed-in value is a copy of the reference to our list object. One of the trouble in python is if you really want to pass a reference to a true value such as an int. Usually I just wrap the int value in a list object because the syntax is fairly concise. Of course if you can you should avoid it, and in python 3 the most common occurrence is fixed with the nonlocal statement (which allows you to access the value of an outer scope, required with closures and non-reference values).
- viraptor 16y agoI'm not sure what you're saying here - care to give some example? The way I understand what you're saying - no - you don't pass "an object". In case of objects in Python, Java and others the value you pass then is a reference to that object. That reference cannot change in the calling scope.