📜  python代码示例中带有for循环的范围函数

📅  最后修改于: 2022-03-11 14:47:05.841000             🧑  作者: Mango

代码示例1
# Syntax - range(start, stop, step) - you must use integers, floats cannot be used

for i in range(3):
    print(i)
# output - automatically taken start = 0 and step = 1, we have given stop = 3 (excluding 3)

for i in range(0, 4):
    print(i)
# output - We have given start = 0 and stop = 4 (excluding 4), automatically taken step =1

for i in range(0, 5, 2):
    print(i)
# output - We have given start = 0, stop = 5 (excluding 5), step = 2

for i in range(0, -4, -1):
    print(i)
# output - We can go even backwards and also to negative numbers