1. Looping over a range of numbers

Avoid creating a list just to loop over a sequence of numbers. Use range instead because it is more concise and more memory-efficient.

range describes a numeric sequence without allocating all of its values up front. That is the normal tool for count-controlled loops, so using it also matches reader expectations.

1.1. Don’t do this

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

1.2. Do this

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