weixin_39836533
2017-09-04 09:37
采纳率: 100%
浏览 2.3k
已采纳

python一个关于while循环的报错问题

girls = ['gujin','yangmi','zhengshuang']
my_girls = []
a = len(girls)
a = int(a)
while a >= 0:
a=a-1
girl = girls.pop()
my_girls.append(girl)
continue
for my_girl in my_girls:
print(my_girl)

报错:
Traceback (most recent call last):

File "girls4.py", line 6, in
girl = girls.pop()
IndexError: pop from empty list

这段执行不报错:
girls = ['gujin','yangmi','zhengshuang']
my_girls = []
while girls:
girl = girls.pop()
my_girls.append(girl)
for my_girl in my_girls:
print(my_girl)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题