Function 1
def scale(data, factor):
for j in data:
j = j * factor
target = [1,2,3,4,5]
factors = 4
scale(target, factors)
print(target)
Output = [1, 2, 3, 4, 5]
Function 2
def scale(data, factor):
for j in range(len(data)):
data[j] *= factor
target = [1,2,3,4,5]
factors = 4
scale(target, factors)
print(target)
Output [4, 8, 12, 16, 20]
Why is it that in the first function i dont get the output but when i use the range function i suddenly do?