2nd Sep 2022, 5:42 AM
Levi
Levi - avatar
1 Answer
+ 3
unless declared the function f will assume the second argument to be 'values'. initialization for any variable made in the function arguments will be only once. so, when you call the function the second time, it assumes the previous value of 'values' in order to obtain your desired results, change your code to this def f(i): values = [] values.append(i) print(values) return values f(1) f(2) f(3) now, 'values' is a local variable and will be empty every time you call the function
2nd Sep 2022, 5:55 AM
Harsha S
Harsha S - avatar