What does range(1,1) return in Python?
漂亮男人
漂亮男人 2017-06-22 11:52:08
0
3
3535
# 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]?

漂亮男人
漂亮男人

reply all(3)
迷茫

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].

三叔
>>> list(range(1,1))
[]
代言

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template