Augustmoon 发表于 2018-8-8 15:52:05

range(0)的相关问题

a = 10
for i in range(0):
        print(a)

请问这个for循环是不是不会执行?

claws0n 发表于 2018-8-8 15:59:54

会执行呀,但是不会打印出任何结果……

如果输入一个参数 x,默认是从 0 开始到 x-1。严格一点应该从数学的角度 [0,x) 右边是没有包含的。现在你(0,0) 就是空集合,所以不会打印

maverick 发表于 2018-8-8 21:49:35

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]
查看完整版本: range(0)的相关问题