Iterating over a list in a function


n = [3, 5, 7]

def total(numbers):
result = 0
for i in range(0,len(numbers)):
result += numbers[i]
return result

What does [i] after numbers do? I replaced it with just “numbers” without [i] and my code didn’t work…


I recommend reading the documentation on iterators to better understand this concept:


Thank you!! I am reading it and trying to understand it! :blush:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.