Suppose we have the function below:
def foo(nums, k):
add = sum(nums[:k])
return add
In the function above, we temporarily create a sub-list of length k
. We then calculate the sum of this sub-list, storing its value in add
.
My question is simple. Since num
stores a numeric value (and no actual reference to the sub-list we just created), once this line executes, do we de-allocate the space for the nums
sub-list of size k
?