表示三个参数,送start开始,stop结束(不包含stop),步长为整数step的序列
range(start, stop, step)
例子1
for i in range(1, 5, 2):
print(i)
# 1
# 3
# 5
# 7
# 9
例子2:可只传入stop参数,此时strat默认值为0,step参数默认值为1
for i in range(3):
print(i)
# 0
# 1
# 2
错误例子,step不能为float型
for i in range(1, 5, 2.0):
print(i)
# TypeError: ‘float‘ object cannot be interpreted as an integer
# step应为int型,不能为float型
原文:https://www.cnblogs.com/moyutime/p/14295720.html