Table of contents
1.
Introduction
2.
What is the Pass Keyword in Python?
2.1.
Syntax
3.
Need of Python Pass Statement
4.
Uses of Pass Statement in Python
5.
Example of Pass Keyword in Python with Implementation
5.1.
Implementation
5.1.1.
Output
5.2.
Implementation
5.2.1.
Output
5.3.
Implementation
5.3.1.
Output
5.4.
Implementation
5.4.1.
Output
6.
Frequently Asked Questions
6.1.
What are the advantages of Python over other programming languages?
6.2.
Why do we need continue keyword?
6.3.
What are modules in Python?
6.4.
What is the difference between a pass and continue keywords in Python?
6.5.
How do you pass code in Python?
6.6.
Is pass a function in Python?
7.
Conclusion
Last Updated: Aug 21, 2025
Easy

Python Pass Statement

Author Shubham Das
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we will discuss the pass keyword in Python. There are various keywords in Python such as if, else, while, for, return, and def. And one such keyword is pass.

What is Pass Keyword in Python?

We will discuss how we can use and implement it. Before moving on to the main topic, let us discuss Python.

What is the Pass Keyword in Python?

In Python, the pass keyword is a null statement, meaning it does nothing and serves as a placeholder. 

pass keyword

The main purpose pass keyword:

  • The primary use of pass is to act as a placeholder within your code's structure. This allows you to maintain the overall structure and indentation without introducing actual functionality at that point.
  • It's helpful in various scenarios:
    • Unfinished code blocks: When you're working on a code block (like a function or loop) but haven't implemented its logic yet, pass can be used temporarily to avoid syntax errors.
    • Conditional statements: In if statements or loops where you might want to add functionality later, pass can be a placeholder until the specific logic is defined.
    • Classes: You might use pass in an empty class definition to indicate it serves as a base class or doesn't have any initial functionality.
      For example, if we use a function, we will face an error if nothing is written inside the function. And we can escape this easily using the pass keyword. We have also implemented this example later in this article. 

Hurray! We have understood the pass keyword in Python. Now let us understand the syntax of the pass keyword in Python.

Syntax

The syntax of the pass keyword in Python is as follows:

pass

Congratulations! We have successfully understood the syntax of the pass keyword in Python. Now let's look at the uses of the pass keyword in Python.

Need of Python Pass Statement

The pass statement in Python serves several important purposes that enhance code readability, maintainability, and development workflow:

  • Placeholder for Unimplemented Functionality: When you're structuring your code, you might encounter situations where you want to define the overall framework (functions, loops, conditional statements) but haven't yet implemented the specific logic within them. Using pass as a placeholder prevents syntax errors while you work on the actual functionality later.
  • Maintaining Code Structure: In some cases, you might have conditional statements (like if statements) or loops where you anticipate adding logic in the future based on certain conditions. Using pass initially ensures the code structure remains valid and avoids potential errors, allowing you to come back and implement the specific behavior later.
  • Empty Class Definitions: While uncommon, pass can be used in empty class definitions. This might be the case for a base class that doesn't have any initial functionality or serves as a placeholder for future inheritance. Using pass in such cases ensures the class structure is valid without introducing unintended behavior.
  • Improved Readability: Strategically using pass can sometimes enhance code readability. For instance, in a loop iterating over a collection, you might initially use pass to indicate the loop's purpose without cluttering it with temporary logic you plan to implement later.

Uses of Pass Statement in Python

Pass statement in Python can act as a saviour for us. It can help us to avoid errors in the following cases:

  • Empty function definitions.
  • Empty class definitions.
  • Empty loops.
  • Empty if statements.

Leaving any function, class definition, loop, or statement empty will throw an error, but using the pass keyword can resolve this problem.
Well done! We have understood the uses of the pass keyword in Python. Now let us look at some examples to know how it is used.

Example of Pass Keyword in Python with Implementation

We can use the pass keyword in an empty function, class definition, if statement, and loop.

Implementation

# Creating a function
def CodingNinjas():
    pass
print("Function was passed successfully")

Output

Function was passed successfully

 

As we discussed above, if we do not use the pass keyword.

def ninjas():

So we will get the error in the output.

def ninjas():
                    ^
SyntaxError: unexpected EOF while parsing

Implementation

# Creating a class
class Ninjas:
   pass
print("Class does not contain anything")
You can also try this code with Online Python Compiler
Run Code

Output

Class does not contain anything

Implementation

# False
if 32>64: 
   print("64")
else:
   # Will get executed without doing anything
   pass 
print("Checking if 32 is greater than 64")
You can also try this code with Online Python Compiler
Run Code

Output

Checking if 32 is greater than 64

Implementation

# Loop from 0 to 29
for i in range(30): 
   if i%2:
       pass
   else:
       print(i)
You can also try this code with Online Python Compiler
Run Code

Output

0
2
4
6
8
10
12
14
16
18
20
22
24
26
28

 

Alright! Now we hope you understood the pass keyword in Python.

Frequently Asked Questions

What are the advantages of Python over other programming languages?

Python is free to use, has simple and short code, has simplified syntax, and has extensive libraries.

Why do we need continue keyword?

The continue keyword is used to terminate the current iteration in a loop, and continue to the next loop.

What are modules in Python?

Python module is a file that contains statements and definitions. A module can define classes, functions, and variables. It may also contain an executable code.

What is the difference between a pass and continue keywords in Python?

The continue keyword forces the loop to start at the next iteration. In comparison, the pass keyword tells that there is no code to execute here.

How do you pass code in Python?

In Python, you can pass code using pass keyword.

Is pass a function in Python?

No, pass is not a function. It's a keyword for a null statement.

Conclusion

In this article, we discussed the pass keyword in Python. We learnt what it is and how we can implement it. We hope this blog on the pass keyword in Python was helpful. You can also refer to other similar articles.

Live masterclass