0
n = [3, 5, 7]

def print_list(x):
    for i in range(0, len(x)):
        print x[i]
        print i

print_list(n)

I thought since the program is iterating through the index, having the range as len(list) would be out of range. However, this is apparently the correct way, and I'm not really sure why. Can somebody explain?

enzo
  • 9,861
  • 3
  • 15
  • 38
John123
  • 11

1 Answers1

0

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops when it reaches the specified number.

https://docs.python.org/3/library/stdtypes.html#range

Kaushal Sharma
  • 1,770
  • 13
  • 16