Multiple optional arguments python

后端 未结 2 409
余生分开走
余生分开走 2021-01-04 22:58

So I have a function with several optional arguments like so:

def func1(arg1, arg2, optarg1=None, optarg2=None, optarg3=None):

Optarg1 &

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 00:00

    If you assign them in the call of the function you can pre-empt which parameter you are passing in.

    def foo( a, b=None, c=None):
        print("{},{},{}".format(a,b,c))
    
    >>> foo(4) 
    4,None,None
    >>> foo(4,c=5)
    4,None,5
    

提交回复
热议问题