Python: passing flags to functions

前端 未结 6 2120
清酒与你
清酒与你 2021-02-09 12:27

For a long time i have been trying to figure out what is the best way to pass flags to python functions. The most straightforward way is something like:

def func         


        
6条回答
  •  Happy的楠姐
    2021-02-09 12:58

    With *args:

    def some_func(data, *args):
        # do something
        return args # this is just to show how it works
    
    
    >>> print some_func(12, 'test', 'test2', 'test3')
    ('test', 'test2', 'test3')
    

    This is a good question to understand how *args and **kwargs work : *args and **kwargs?

提交回复
热议问题