Answers for "UnboundLocalError: local variable 'msg' referenced before assignment"

1

UnboundLocalError: local variable 'r' referenced before assignment

r = 0
list = ['apple','lime','orange']
def list_list(x):
    for i in x:
        r +=1
        print r
list_list(list)
Posted by: Guest on May-12-2021
0

UnboundLocalError: local variable 'obj' referenced before assignment

UnboundLocalError: local variable 'obj' referenced before assignment
Posted by: Guest on June-03-2021
0

UnboundLocalError: local variable 'msg' referenced before assignment

Hey Mate, 

Issue is that you're calling variable r inside the def list_list. 
(reccomend to always keep your def on top or in another .py file to avoid this confusion)
happy coding.
Try:

def list_list(x, y):
    for i in x:

        y +=1
    print (y)

r = 0
list = ['apple','lime','orange']
list_list(list, r)
Posted by: Guest on October-11-2021

Code answers related to "UnboundLocalError: local variable 'msg' referenced before assignment"

Browse Popular Code Answers by Language