+ 2
Arguments and returnings
I need to know if we can modify the variable that I give to function, like this: i=0 function(i) print(i) and the output is something else. There's a way to do that?
3 Answers
+ 13
You could have the function return the new value, and then reassign the variable with it. Ex:
def function(x)
#Your code
return x
i = 0
i = function(i)
print(i)
+ 13
No, Python doesn't have means of passing basic/primitive types (int, string, etc) by reference. Although it's not the best practice, returning a list of values you want and picking them apart afterward is a workaround.
+ 1
That is a possible solution but in c++ we can use pointers and in python we can do something like it?