• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Python if else do nothing – Using pass Statement to Do Nothing in Python

Python if else do nothing – Using pass Statement to Do Nothing in Python

February 4, 2022 Leave a Comment

To tell Python to do nothing, we can use the pass statement. For example, in an if-else block, if a condition holds, we can tell Python to move on to the next block of code.

if x == 2: 
    pass  #pass tells Python to do nothing

In Python, the pass statement is very useful for controlling the flow of your program. With the pass statement, we can tell Python to do nothing.

For example, let’s say we have the following if-else block and we want to check if a variable is equal to 10. For this example, we want that if the variable is equal to 10, let’s just move on to the next block of code.

To accomplish this, we can use the pass statement and Python will do nothing if the if statement holds.

if x == 10: 
    pass  #pass tells Python to do nothing

Doing Nothing After Else in Python

In the same way as above, we can use the Python pass statement to do nothing if we want to do nothing in an else statement.

Let’s say we are in a similar situation as above, but in this case, we want to do nothing in the else statement.

To accomplish this, we will use the pass statement in the else block.

if x == 10: 
    do_something()
else: 
    pass#pass tells Python to do nothing

Hopefully this article has been helpful for you to learn how to do nothing in Python with the pass statement.

Other Articles You'll Also Like:

  • 1.  Remove Specific Word from String in Python
  • 2.  Get Tomorrow’s Date as Datetime in Python
  • 3.  PROC MIXED Equivalent in Python for Least Squared Means ANOVA
  • 4.  Touch File Python – How to Touch a File Using Python
  • 5.  Python Get Operating System Information with os and platform Modules
  • 6.  Python Random Uniform – Generate Random Numbers Uniformly in Range
  • 7.  How to Multiply Two Numbers in Python
  • 8.  Solve Python Object Does Not Support Indexing Error
  • 9.  Initialize Multiple Variables in Python
  • 10.  Python sin – Find Sine of Number in Radians Using math.sin()

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy