sandwich_orders = ["pastrami","vegetable","chicken","pastrami","pastrami"]
finished_sandwiches = []
#while sandwich_orders:
for sandwich_order in sandwich_orders:
print("I made your " + sandwich_order + " sandwich")
sandwich_orders.remove(sandwich_order)
输出是:
I made your pastrami sandwich
I made your chicken sandwich
I made your pastrami sandwich
如果不注释掉 while 语句,就可以全部输出:
I made your pastrami sandwich
I made your chicken sandwich
I made your pastrami sandwich
I made your vegetable sandwich
I made your pastrami sandwich
请问为什么只用 for 语句会出现输出不完整的情况?添加了 while 语句后为什么可以避免出现问题?
finished_sandwiches = []
#while sandwich_orders:
for sandwich_order in sandwich_orders:
print("I made your " + sandwich_order + " sandwich")
sandwich_orders.remove(sandwich_order)
输出是:
I made your pastrami sandwich
I made your chicken sandwich
I made your pastrami sandwich
如果不注释掉 while 语句,就可以全部输出:
I made your pastrami sandwich
I made your chicken sandwich
I made your pastrami sandwich
I made your vegetable sandwich
I made your pastrami sandwich
请问为什么只用 for 语句会出现输出不完整的情况?添加了 while 语句后为什么可以避免出现问题?
