Python's `range` function with 3 parameters

流过昼夜 提交于 2019-11-30 17:43:26

问题


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



来源:https://stackoverflow.com/questions/32096391/pythons-range-function-with-3-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!