Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Global in Nested Functions

def foo():
    x = 20

    def bar():
        global x
        x = 25
    
    print("Before calling bar: ", x)
    print("Calling bar now")
    bar()
    print("After calling bar: ", x)

foo()
print("x in main: ", x)
 
PREVIOUS NEXT
Tagged: #Python #Global #Nested #Functions
ADD COMMENT
Topic
Name
3+4 =