5. Looping over a range of numbers

The key is to avoid creating an array. Use the range function instead as it will make your code more concise and is more memory efficient.

5.1. Don’t do this

1for i in [0, 1, 2, 3, 4, 5]:
2    print(i ** 2)

5.2. Do this

1for i in range(6):
2    print(i ** 2)