Sitemap

How To Easily Use Python Pass Statement

2 min readJun 25, 2023

--

In this Python guide, we’ll learn how to use Python pass statement with proper code examples. In order to give you a proper idea of how Python pass is used, we’ll be explaining these examples step by step.

After reading this post, you’ll have a complete idea of how to use Python pass statement in code.

So let’s not delay anymore and just get right into its implementation.

What is Python Pass?

It is actually a null statement that you can use within Python loops , if statements, functions and classes.

Suppose you want to specify an if statement but don’t want to pass anything as you would want to specify a code inside its body in the future. If you specify it without passing something to its body, then Python will give an error as the body cannot be empty.

So this is the reason that we use Python pass statement in it. Python does not ignore it but no action is performed by it as it is actually just a null statement.

Get Zeeshan Ali’s stories in your inbox

Join Medium for free to get updates from this writer.

Let’s now understand it using multiple practical examples. But first, let’s walk through its syntax.

Syntax of Pass Statement

pass

It can be implemented using this simple pass keyword.

Implementing Python Pass Statement (Multiple Examples)

Below examples will satisfy the purpose of pass statement in Python code.

Example 1: Use Comment inside If Statement

Let’s pass a comment inside if statement and see if it works. See below code:

i=3
if(i==4):
# will specify actions later

Output

SyntaxError: unexpected EOF while parsing

In Python, comments are completely ignored which means nothing is actually passed to the body of if statement. As a result, we got a syntax error. Continue reading…

--

--

Zeeshan Ali
Zeeshan Ali

Written by Zeeshan Ali

I am a Python developer and I am here to share what i have learnt so far. Hope my posts will help you in your python development journey. www.letmeflutter.com