Passing an Array/List into Python

前端 未结 5 2101
耶瑟儿~
耶瑟儿~ 2020-12-12 13:31

I\'ve been looking at passing arrays, or lists, as Python tends to call them, into a function.

I read something about using *args, such as:

def some         


        
5条回答
  •  无人及你
    2020-12-12 14:32

    You don't need to use the asterisk to accept a list.

    Simply give the argument a name in the definition, and pass in a list like

    def takes_list(a_list):
        for item in a_list:
             print item
    

提交回复
热议问题