
上QQ阅读APP看书,第一时间看更新
3.10 内置函数range
:深入讨论
range
函数还有两参数和三参数两个版本。前面演示了range
带有一个参数时,会生成一系列连续的整数,从0到(但不包括)参数的值。range
函数的两参数版本会生成从其第一个参数值开始到(但不包括)第二个参数值为止的一系列连续的整数,例如:

range
函数的三参数版本会生成从第一个参数的值开始到(但不包括)第二个参数的值为止,并以第三个参数值(称为步长)递增的整数序列,例如:

如果第三个参数的值为负,则序列从第一个参数的值向下进行,到达(但不包括)第二个参数的值,其中,按第三个参数的值递减,例如:
