简体   繁体   中英

Call a function with optional parameter with default value?

I need to call the following function.

def f(p):
    # .....
    g(p)

and p of g(p) is optional

def g(p=some_default_value):

I actually need f(p) to call g() without p (I don't know some_default_value and it may change). However, p of f(p) is required. Is it a way to set p to some special value to let f call g with the default value of p ?

f(p=..?..)

Simply do

def g(p=None):
    pass

def f(p):
    g()

As long as you don't pass in p in g() , it is not taking anything in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM