📅  最后修改于: 2022-03-11 14:46:39.495000             🧑  作者: Mango
#Perfect if you want to store a mathematical expression without defining the
#variables used:
my_function = "5x**2 + 8x - 2" #I want to define the function cleanly as a
# variable
#insert definition of other varianles here
#insert other code here
def f(x): #Defining the function as the funtion f(x)
return eval(my_function) #Returning my_function with the x in f(x) as x
print(f(0)) #Printing f(0), thereby returning my_function with 0 as x
#Returns -2