Variables in Python are not passed by reference, and there is no way to do so. So a function that takes an integer argument and just increments it can never impact the original variable. If you want to modify the original variable, you will have to assign it a new value instead.
def secondary_function(var):
return var + 1
variable = 1
variable = secondary_function(variable) # variable is now 2
Similary, you will have to modify your function function too to return the value instead:
def function (parameter_1, parameter_2, action = None, var = None):
if parameter_1 == 1:
return action(var)
variable = function(1, 2, secondary_function, variable)
Python has no notion of pass-by-reference or pass-by-value. Instead, every variable is passed by assignment. That means that whenever you call a function and pass a variable, the behavior is the same as if you just did function_argument = variable; you are assigning the value of the source variable to the function argument. Since Python is object oriented, this effectively means that you copy the reference to the object that variable refers to. As such, when the object is mutable, you can modify it and impact other variables referencing the same object. But for immutable objects (ints, strings, tuples, etc.), you cannot modify the existing object, so when you “modify” it, you always assign a new object to the variable, without affecting all the other variables that still point to the old object.