两个Python关键字之间有什么显着差异吗continue
and pass
就像例子中一样
for element in some_list:
if not element:
pass
and
for element in some_list:
if not element:
continue
我应该注意什么?
是的,他们做完全不同的事情。pass
只是什么都不做,而continue
继续下一个循环迭代。在您的示例中,如果您在if
: 执行后pass
,该进一步的语句将被执行。后continue
,不会的。
>>> a = [0, 1, 2]
>>> for element in a:
... if not element:
... pass
... print(element)
...
0
1
2
>>> for element in a:
... if not element:
... continue
... print(element)
...
1
2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)