search

Home  >  Q&A  >  body text

What does range(1,1) return in Python?

# Python杨辉三角实现
def yanghuiTriangle():
    L = [1]
    L2 = []
    while True:
        yield L
        L = [1]+[L[x-1]+L[x] for x in range(1,len(L))]+[1]#这里如果是range(1,1)的情况前面的L[0]和L[1]中不是取不到值吗?
for item in yanghuiTriangle():
    print(item)
    if len(item)>10:
        break

L = [1] [L[x-1] L[x] for x in range(1,len(L))] [1]#If it is range(1,1), the previous L Aren't there values ​​that cannot be obtained from [0] and L[1]?

漂亮男人漂亮男人2738 days ago3573

reply all(3)I'll reply

  • 迷茫

    迷茫2017-06-22 11:54:08

    When

    L = [1], range(1,len(L)) is range(1, 1) and returns [], an empty list, so there is no number of iterations through for. So Get the second row of Yang Hui's triangleL = [1] + [1] = [1, 1].

    reply
    0
  • 三叔

    三叔2017-06-22 11:54:08

    >>> list(range(1,1))
    []

    reply
    0
  • 代言

    代言2017-06-22 11:54:08

    list(range(1,1)) is equivalent to returning [] yield and ends recursively.

    reply
    0
  • Cancelreply