Q:

How to modify local variable in a function in Python?

I would like to change the value of a parameter in an imported function without putting it as input. For instance:
# in def_function.py
def test(x):
    parameter1 = 50 # default value
    return parameter1*x

# in main.py
from def_function import test
print(test(1)) # It should give me 50
parameter1 = 10 # changing the value of parameter1 in test function
print(test(1)) # It should give me 10

A:

parameter1 inside the function is in its own scope. It's not the same as the parameter1 outside the function definition.
To do what you're trying to do, add a keyword argument to the function definition, providing a default value for the argument:
# in def_function.py
def test(x, parameter1=50):
    return parameter1*x

# in main.py
from def_function import test
print(test(1)) # It gives 50
print(test(1, parameter1=10)) # It gives 10 (as a keyword arg)
print(test(1, 10)) # It gives 10 (as a positional arg)

Don't use globals if you can help it.

