Python的`range`函数带有3个参数 [英] Python's `range` function with 3 parameters

查看:729
本文介绍了Python的`range`函数带有3个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道下面一行会给出给定的结果:

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

for in range(5):
   print(i)



0
1
2
3
4

0 1 2 3 4

但我不明白如果添加3个单独的参数会导致混淆。这是如何返回这些特定的结果? (4 6和8)????

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

4 6 8

推荐答案

从4开始,然后增加2,结束于8,因为 10 < 10 是假的。所以 4 6 8

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

这篇关于Python的`range`函数带有3个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆