There are 3 ways to call the range
in Python:
range(INI, FIM, INC)
, this is, shall we say, the basic form of range
in Python. The range starts with value INI
, being incremented by the value INC
at each iteration until it reaches or exceeds the value of FIM
; follows the following formula, to i
rising from scratch:
range(INI, FIM)
, in this case, it is assumed that the increment value INC
be unitary;
range(FIM)
; in this case, it is assumed that the start INI
is 0 and the increment INC
be unitary.
It is always worth noting that the interval is closed at the beginning (i.e., includes INI
) and open at the end (i.e., it does not arrive in FIM
, for exactly in the previous step).
Taking possession of this knowledge, use the best semantics for your problem. In your particular case, I believe you wish to use these values only for user interaction, not in the internal logic of your program. If this is the case, the ideal is to do as the answer of Anthony Gabriel: only the display is treated to inform user-friendly indexes, making the use of the internal index more friendly to the code.
UPDATE
In case the iteration does not favor the internal logic of the iteration, the Gypsy Morrison Mendez is more performative and direct to the point.
I must admit that I am biased to start ties by zero, so by pure prejudice I would lose this micro optimization.
Note that you do not need to coerce the
range
in alist
to be able to iterate. Therange
is a generator (yielder
), a cool stop that can handle a list of 5 million elements (or more!, has examples of Python generators that go to infinity) using almost nothing in memory– Jefferson Quesado