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)
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)
UnboundLocalError: local variable 'obj' referenced before assignment
UnboundLocalError: local variable 'obj' referenced before assignment
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us