Home > Net >  How to use the result of one function as a parameter of a new function in python?
How to use the result of one function as a parameter of a new function in python?

Time:11-15

For example:

def title(a,b):
   ...
 
def movie( c = title, d):
     ...

But I get : NameError: name 'title' is not defined

How can I use function 'title' in function 'movie' ?

I have try:

def movie(title(a, b), c):

But SyntaxError: invalid syntax now.

CodePudding user response:

When you call the function in movie, also give it parameters (your a and b) Like:

movie(title(a, b), c)

CodePudding user response:

def add(a, b):
    return a   b

def mult(c, d):
    return c * d

print(mult(add(2, 2), 3))
#          ^   ^  ^   ^
#          |   |  |   |
#function "c"=(a  b),*d

# (2   2) x 3 = 12
#  ^   ^    ^
#  |   |    |
#  a   b    d
  • Related