def function(x):
x = 4
variable = 0
function(variable)
print(variable)
This would output 0 but is there a way that it outputs 4? And also it should be without return.
def function(x):
x = 4
variable = 0
function(variable)
print(variable)
This would output 0 but is there a way that it outputs 4? And also it should be without return.
First of all, I'd suggest you take a look to this nice explanation about python names and values. Now, one possible way to achieve what you want would be using a mutable structure as a dictionary, so you can pass your variable inside, something similar to this would do it:
def function(dct):
dct['variable'] = 4
dct = {
'variable': 0
}
function(dct)
print(dct['variable'])
More info can be found in python docs