Discuss / Python / 死循环

死循环

Topic source

大洋芋D

#12 Created at ... [Delete] [Delete and Lock User]

最后的i=1强制赋值,输出的名字永远是L[0] 死循环很简单,当索引脚标到达最后一个元素的时候,重新赋值为0即可 看我的: names=['Bart','Lisa','Adam'] i=0 while True: print('Hello,'+names[i]) i+=1 if i==3: i=0

L = ['Bart', 'Lisa', 'Adam'] n = 0 while n < 3: print ('hello ,',L[n]) n += 1


  • 1
  • 2

Reply