Why this code is giving local variable access error when I am accessing
a global variable?

p = 0
def visit():
    m = 1
    if m > p:
        p = m

visit()
print(p)

If I change the variable assignment inside the function to q = m then it
works fine. Like this

p = 0
def visit():
    m = 1
    if m > p:
        q = m    # Changed 'p' to 'q'

visit()
print(p)

-- 
Pankaj Jangid
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to