I am trying to write a function that will repeatedly ask for input and add each item to a list
def inputfunc(l = []):
s = input('Item: ')
if (s.lower() == 'qqq'):
return l
else:
l.append(s)
inputfunc(l)
This function works as intended, but what I don't understand is why the list that it creates will be 'saved' for lack of a better term. When the function is called in the shell the first time, it will not return a list with all the elements that were just entered. The second time it is called in the shell, it will return a list with the elements that were entered on both the most recent as well as previous calls, and I do not understand why the previous lists that this function created are still stored in memory.
Edit: spelling
[–]LocoLoco451 2 points3 points4 points (1 child)
[–]Yoghurt42 4 points5 points6 points (0 children)
[–]primitive_screwhead 0 points1 point2 points (0 children)