Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

python - How to pass values to a formula?

How Do I pass values say 12,32,34 to formula x+y+z in python without assigning manually? I have tried using **args but the results is None.

def myFormula(*args):
    lambda x, y: x+y+z(*args)
print(myFormula(1,2,3))
question from:https://stackoverflow.com/questions/65661996/how-to-pass-values-to-a-formula

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

formula = lambda x,y,z: x+y+z
print(formula(1,2,3))

there is no need to use *args there.

here is an example of using a function for a formula

# a = (v - u)/t
acceleration = lambda v, u, t: (v - u)/t
print(acceleration(23, 12, 5)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...