Pythonpass details and instance code

Source: Internet
Author: User
This article mainly introduces the details of Pythonpass and the related information of the instance code. For more information, see Python pass usage:

  1. Empty statement do nothing
  2. Complete format
  3. Complete semantics

Take the if statement as an example. in c or c ++/Java:

If (true); // do nothingelse {// do something}

For Python, write as follows:

If true: pass # do nothingelse: # do something

1. Role of pass statements in functions

When you write a program, the execution of the statement is not completed yet. in this case, you can use the pass statement to hold the space, or use it as a tag, which is the code to be completed later. For example:

Def iplaypython (): pass

Define a function iplaypython, but the function body is not completed yet, and content cannot be left empty. Therefore, pass can be used to replace the occupied position.

2. Role of the pass statement in the loop

Pass is also commonly used to compile an empty body for a composite statement. for example, if you want an infinite loop of a while statement, no operation is required for each iteration. you can write it like this:

While True: pass

The above is just an example. In reality, it is best not to write such code, because the execution code block is pass, that is, nothing is done, and python will enter an endless loop.

Thank you for reading this article. I hope it will help you. thank you for your support for this site!

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.