What range is set by range in Python?

-4

When I define

for i in range (5):

My range goes through 0,1,2,3,4,5 or 1,2,3,4,5

    
asked by anonymous 27.06.2018 / 15:22

2 answers

1

Will generate 0, 1, 2, 3 and 4 Normally, the first range parameter is the starting number, the second is the final but excluding. In your example, range (5), python assumes that the initial parameter is equal to 0. It will generate the numbers based on this condition: greater / equal to zero and less than 5.

    
27.06.2018 / 16:05
-1

In Python the count starts from zero, then:

list(range(5))
[0,1,2,3,4]
    
27.06.2018 / 15:28