Python Pass detailed introduction and instance code _python

Source: Internet
Author: User

Usage of Python Pass:

  1. Empty statement do nothing
  2. Guaranteed Format Integrity
  3. Ensure semantic integrity

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

if (true)
;  Do nothing
else
{
  //do something
}

This corresponds to Python:

If true: Pass
  #do Nothing
else:
  #do Something

The role of 1 pass statement in function

When you write a program, the execution of the statement part of the idea has not been completed, then you can use the PASS statement to occupy a bit, but also as a token, is to be completed after the code. Let's say this:

Def Iplaypython (): Pass
  

Define a function Iplaypython, but the function body part is not completed temporarily, and cannot empty not write content, so can use pass to replace occupies a position.

The function of 2 pass statement in circulation

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

While True: Pass
  

Just for example, it's best not to write code like this, because the execution code block does nothing for pass, where Python goes into a dead loop.

Thank you for reading, I hope to help you, thank you for your support for 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.