Python Pass details and example code

Source: Internet
Author: User
How to use the Python pass:

  1. Empty statement does nothing
  2. Guaranteed Format Complete
  3. Guaranteed Semantic Integrity

Take the IF statement as an example, in C or C++/java:

if (true);  Do nothingelse{  //do something}

This is what Python should write:

If true:  pass #do nothingelse:  #do Something

1 function of pass statements in functions

When you are writing a program, the execution of the statement part of the idea is not complete, you can use the PASS statement to occupy a bit, can also be used as a token, is to be completed after the code. such as the following:

Def iplaypython ():  Pass

A function iplaypython is defined, but the function body part is not finished yet, and cannot be empty without writing the content, so it is possible to replace the position with a pass.

2 The function of the pass statement in the loop

Pass is also often used to write an empty body for a compound statement, for example, you want an infinite loop of a while statement, no action is required for each iteration, you can write:

While True:  Pass

Just for example, in reality it is best not to write this code, because the code block for the pass is the empty do nothing, then Python will enter the dead loop.

Thank you for reading, hope to help everyone, thank you for the support of this site!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.