Scoping

In [5]:
# foo is defined in the 'global' scop
foo = 10

def main():
    # bar is in the 'local' scope
    bar = 20
    print(foo, bar)

# This is an error due to scoping  
#print(bar)
In [4]:
main()
10 20
In [16]:
data = []

def add_data():
    global data
    data = data + [1,2,3,4]
    #data.extend([1,2,3,4])
    print(data)
    
add_data()
[1, 2, 3, 4]
In [ ]: