Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
HowToDoInJava
  • Java
  • Spring AI
  • Spring Boot
  • Hibernate
  • JUnit 5
  • Interview

Python pass Statement

The Python pass statement is used to execute an empty statement. We can use the pass statement when we do not want to execute any statement at a place in the code, but Python requires us to specify a statement to satisfy the Syntax rules. Python pass statement …

Lokesh Gupta

October 1, 2022

Python Flow Control
Python Basics
Python

The Python pass statement is used to execute an empty statement. We can use the pass statement when we do not want to execute any statement at a place in the code, but Python requires us to specify a statement to satisfy the Syntax rules.

Python pass statement is different than a Python comment. A comment is totally ignored by the Python interpreter, but pass sstatement is not ignored.

Python pass Statement Example

The for loop in Python requires at least one statement to execute. If we do not write any statement under for loop body, the program will give an error.

If for some strange reason, we want to loop through a sequence but do not want to execute any statement, we can use pass statement.

names = ["alex", "brian", "charles"]

for x in names:
  pass

print("Statement after the loop body")

Program output.

Statement after the loop body

The pass Block

Please note that pass statement does not work as the break statement. It does not pass the whole code block.

The pass statement only passes the single statement. If there are other statements in scope of pass block, they will be executed.

names = ["alex", "brian", "charles"]

for x in names:
  pass
  print(x)

print("Statement after the loop body")

Program output.

alex
brian
charles
Statement after the loop body

Happy Learning !!

Comments

Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Python Tutorial

  • Python Introduction
  • Python Install in Sublime
  • Python Keywords
  • Python Comments
  • Python Variables
  • Python Data Types
  • Python Type Conversion
  • Python Examples

Python Flow Control

  • Python if…else
  • Python for Loop
  • Python while Loop
  • Python break
  • Python continue
  • Python pass

Python Datatypes

  • Python Integer
  • Python String
  • Python List
  • Python Tuple
  • Python Set
  • Python Dictionary
  • Python OrderedDict
  • Python Priority Queue

Python Modules

  • Python Bcrypt
  • Python Hashlib
  • Python Httplib2
  • Python JSON

Python Advanced Topics

  • Python CSV Files
  • Building a Recommendation System

Python Reference

  • Built-in Functions
  • String Functions
Photo of author

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Follow on Twitter Portfolio

Previous

Python continue Statement

Next

Python input()

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Tutorial Series

OOP

Regex

Maven

Logging

TypeScript

Python

Meta Links

About Us

Advertise

Contact Us

Privacy Policy

Our Blogs

REST API Tutorial

Follow On:

  • Github
  • LinkedIn
  • Twitter
  • Facebook
Copyright © 2026 | Sitemap