all Python 3Loopsconstruct
pass
control
The empty statement: it does nothing. It fills a place where the syntax demands a block but there is no code yet — a function, class, if or except body.
Syntax
def todo():
pass
A common mistake is to think pass inside a loop skips the iteration: it does nothing, and the code after it in the same iteration still runs. Skipping the rest of the iteration is what continue does. You can write ... (Ellipsis) instead of pass — an expression that also does nothing; by convention ... marks stubs and protocols, while pass marks an intentionally empty block. The risky case is except: pass — the error vanishes without a trace, and you end up hunting it blind.
Examples
out_pass, out_cont = [], []
for i in range(4):
if i % 2:
pass # ничего не делает
out_pass.append(i)
for i in range(4):
if i % 2:
continue # переходит к следующей итерации
out_cont.append(i)
print(out_pass) # → [0, 1, 2, 3]
print(out_cont) # → [0, 2]
class Plugin:
pass
def later():
...
print(later()) # → None
print(Plugin.__name__) # → Plugin
See also
Open in the full glossarydocs.python.orgReport an inaccuracy