python - How can I avoid this "variable referenced before assignment"? -
this question has answer here:
ran following problem. it's simple solution, , has been asked here before, couldn't find it.
def a(): lia = [] def b(): in lia: += 1 lib = generatelist() in lib: -= 1 lia = lib def generatelist(): return [1,2,3,4] b() a()
unboundlocalerror: local variable 'lia' referenced before assignment
lia
variable in b()
function never initialized.
so, should edit code in followed way:
def a(): lia = [] def b(lia): in lia: += 1 lib = generatelist() in lib: -= 1 lia = lib def generatelist(): return [1,2,3,4] b(lia) a()
hope helped you!
Comments
Post a Comment