python decompose a list

前端 未结 4 2004
孤街浪徒
孤街浪徒 2020-12-04 01:45

I remember I once seen a operator which is able to decompose a list in python.

for example

[[1],[2],[3]]

by applying that operator

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 02:22

    If you want to pass a list of arguments to a function, you can use *, the splat operator. Here's how it works:

    list = [1, 2, 3]
    function_that_takes_3_arguments(*list)
    

    If you want to assign the contents of a list to a variable, you can list unpacking:

    a, b, c = list # a=1, b=2, c=3
    

提交回复
热议问题