python 之 内置函数 range()

python有很多内置函数 ,参考链接http://www.runoob.com/python/python-built-in-functions.html。下面来讨论下 range()的用法:
语法结构: range(start,end,step=默认1)

>>> range(1,4)                                    #不包括第二个数,开区间
[1, 2, 3]
>>> range(4)
[0, 1, 2, 3]
>>> range(1,4,2)                                # 步长为2
[1, 3]
>>>range(4,0,-1)                             #倒叙
[4,3,2,1]

猜你喜欢

转载自blog.csdn.net/qq_40443457/article/details/87881875