range(0)的相关问题
a = 10for i in range(0):
print(a)
请问这个for循环是不是不会执行? 会执行呀,但是不会打印出任何结果……
如果输入一个参数 x,默认是从 0 开始到 x-1。严格一点应该从数学的角度 [0,x) 右边是没有包含的。现在你(0,0) 就是空集合,所以不会打印 range(start, stop[, step])
This is a versatile function to create lists containing arithmetic progressions. It is most often used in for loops. The arguments must be plain integers. If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. The full form returns a list of plain integers . If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. step must not be zero (or else ValueError is raised). Example:
>>> range(10)
>>> range(1, 11)
>>> range(0, 30, 5)
>>> range(0, 10, 3)
>>> range(0, -10, -1)
>>> range(0)
[]
>>> range(1, 0)
[]
页:
[1]