Here is my code
i got two different output which are [2] and [2,4,6], can someone do some explanation?
list = [1,2,3]
def getdouble(l):
result = []
for i in l :
i = i * 2
result.append(i)
return result
print getdouble(list)
def getdouble_v2 (l):
result = []
for i in range(len(l)):
l[i] = l[i] * 2
result.append(l[i])
return result
print getdouble_v2(list)
The only way to get the output you claim is if the indentation in your file is broken. Verify that you’re not mixing spaces and tabs with
python -tt.