Global variable used in various functions

1

I have this code:

donos=[]
def calcula_media():

    lista_dicionario= [1,2,3]
    donos.extend(lista_dicionario)

def funcao2():

    print donos

How can I do to use the global variable in the 2nd function using what I used in 1º to make it extend , that is, get the [1,2,3] in the 2nd function?

    
asked by anonymous 28.04.2016 / 22:25

1 answer

2

So I just needed to call the functions:

donos=[]
def calcula_media():
    lista_dicionario = [1,2,3]
    donos.extend(lista_dicionario)

def funcao2():
    print(donos)

calcula_media()
funcao2()

See working on ideone .

Ideally in real code in complex application, the best thing to do is not to use global variables like this and always pass as argument.

    
28.04.2016 / 22:45