I saw someone posted the following answer to tell the difference between if x: pass
and if x: 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
What is the result for if not element
when a = 0
? Why when using continue
, 0 is not printed?
continue
is saying "next value in loop please"? And only "continue" if theif
statement isFalse
? – Larrikin