Passing an Array/List into Python

前端 未结 5 2100
耶瑟儿~
耶瑟儿~ 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 can pass lists just like other types:

    l = [1,2,3]
    
    def stuff(a):
       for x in a:
          print a
    
    
    stuff(l)
    

    This prints the list l. Keep in mind lists are passed as references not as a deep copy.

提交回复
热议问题