Jul-29-2019, 11:48 PM
I can get a for loop or while loop to modify a variable outside them, but I can't figure out how to get a function to do that.
# THIS WORKS list_len = 0 while list_len < 100: list_len += 1 print(list_len)
# THIS DOES NOT WORK list_len = 0 def list_inc(): list_len += 1 list_inc() # UnboundLocalError: local variable 'list_len' referenced before assignment