Python- for - append() - pop()-金字塔1

>>:金字塔1

代码:

复制代码
numbers2 = []
for value in range(0,10):
    number = value+1
    numbers2.append(number)
    print(numbers2)

for value2 in numbers2:
    number2 = value2-1
    munbers2 = numbers2.pop(-1)
    print(numbers2)

for value2 in numbers2:
    number2 = value2-1
    munbers2 = numbers2.pop(-1)
    print(numbers2)    
    
for value2 in numbers2:
    number2 = value2-1
    munbers2 = numbers2.pop(-1)
    print(numbers2)   
    
print("\n")
print(len(numbers2))
复制代码

输出结果:

复制代码
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]


1
posted @ 2020-05-04 18:23  大序列  阅读(209)  评论(0编辑  收藏  举报