For循环在python2中不打印列表中的所有内容

2024-06-16 18:07:38 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么这个for循环没有打印列表/数组中的所有内容?例如,列表sentence有值[0, 2],但它只打印出0

# this variable is global, meaning it can be used everywhere.
numbers = []

def looping(number, increment):
    i = 0
    while i < number:
        print "At the top of i is %d" % i
        numbers.append(i)

        i = i + increment
        print "Numbers now: ", numbers
        print "At the bottom of i is %d" % i


looping(2, 2)

print "The numbers: "

for num in numbers:
    print num

Tags: ofthenumber内容列表foris数组