Expanding tuples into arguments

后端 未结 5 1510
逝去的感伤
逝去的感伤 2020-11-22 11:39

Is there a way to expand a Python tuple into a function - as actual parameters?

For example, here expand() does the magic:

some_tuple =          


        
5条回答
  •  囚心锁ツ
    2020-11-22 12:34

    myfun(*some_tuple) does exactly what you request. The * operator simply unpacks the tuple (or any iterable) and passes them as the positional arguments to the function. Read more about unpacking arguments.

提交回复
热议问题