I was practicing a bit with a fairly new language for me, so I tried to write a simple function to add the elements of a list formed by integers, I then wrote a wrong program, and I realized that the variable on which it is iterated increases by two, ie:
lista = [1, 2, 3, 4]
def suma(lista):
for i in lista:
i += i
return i
The final result is 8, then add two units in each iteration, although the program is wrong should not result in 4 and not 8? , I'm missing something but I do not know what it is. Thank you
EDIT:
If we write the following equivalent program:
def suma(lista):
for i in lista:
i += i
print( i)
return i
We obtain the following result:
2
4
6
8
8
?????? The last 8 corresponds to the return