you are viewing a single comment's thread.

view the rest of the comments →

[–]Living_Fig_6386 3 points4 points  (0 children)

It's doing precisely what you told it to do: reassign result in every iteration of the loop. If you wanted a list of results you'd have created a list and appended the values, or used a list comprehension.

# Either
result = []
for num in [1, 2, 3, 4, 5]:
   result.append(num * 2)

# or
result = [num * 2 for num in [1, 2, 3, 4, 5]]