Dec 152020
理解这个地方其实是有难度的,必须动手练习。
for i in 'hello': if i=='l': continue else: print(i,end='') print() for i in 'hello': if i=='l': break else: print (i,end='') print() print ('跳出循环时候的i的值',i)
说一下我自己的理解。break,就是跳出循环,往下走。continue,往上继续运行。
第一段代码,当i==l 是True, 触发continue,往上继续运行,而不会运行print, 最后你会发现输出的时候,少了2个l。
第二段代码,当 i==l,直接跳出循环,终止,
heo he 跳出循环时候的i的值 l