In the line 'p' : equation_calc(p)
you store the result of the function to the key 'p'
. But this result is still an immutable object. What you want instead is to store the reference to the function itself, which you can then call later with your arguments.
val_dict = {
'p' : equation_calc
}
for p in [0, 1]:
print(val_dict['p'](p))
If you function is of the form def function(args): return value
, and the value expression is short, you can also use a lambda expression, like this
val_dict = {
'p' : lambda p: p / 15
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…