Python return list from function

后端 未结 8 957
面向向阳花
面向向阳花 2020-12-13 08:27

I have a function that parses a file into a list. I\'m trying to return that list so I can use it in other functions.

def splitNet():
    network = []
    f         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 09:19

    You may declare the name of the variable assigned to the list as global, like this:

    def get_list():
        global destination_list
        destination_list = []
        destination_list.extend(('1','2','3'))
        return destination_list
    
    get_list()
    print(destination_list)
    

提交回复
热议问题