我有一个循环列表,我想look在达到之后跳过3个元素.在这个答案中提出了一些建议,但我没有充分利用它们:
song = ['always', 'look', 'on', 'the', 'bright', 'side', 'of', 'life']
for sing in song:
if sing == 'look':
print sing
continue
continue
continue
continue
print 'a' + sing
print sing
Run Code Online (Sandbox Code Playgroud)
continue当然四次是胡说八道,使用四次next()是行不通的.
输出应如下所示:
always
look
aside
of
life
Run Code Online (Sandbox Code Playgroud)