Python pass keyword

Example

Create a placeholder for future code:

for x in [0, 1, 2]:
  pass

Run Instance

Definition and Usage

The pass statement is used as a placeholder for future code.

Nothing happens when the pass statement is executed, but it can prevent errors from occurring in situations where empty code is not allowed.

Empty code is not allowed in loops, function definitions, class definitions, or if statements.

More Examples

Example 1

Using the pass keyword in function definition:

def myfunction:
  pass

Run Instance

Example 2

Using the pass keyword in class definition:

class Person:
  pass

Run Instance

Example 3

Using the pass keyword in if statements:

a = 33
b = 200
if b > a:
  pass

Run Instance