Python's `range` function with 3 parameters

2019-02-21 06:38发布

问题:

I understand that the following line will give the given result:

for in range(5):
   print(i)

0 1 2 3 4

But I don't understand how if adding 3 separate parameters the result is confusing. How is this returning these particular results? (4 6 and 8) ????

for i in range(4, 10, 2):
 print(i) 

4 6 8

回答1:

Starts at 4, then increments by 2, to end at 8 because 10 < 10 is false. So 4 6 8