Python's If statement

Source: Internet
Author: User

computers can do a lot of automated tasks, because it can make their own conditions to judge. Output Results

    1. Note: the indentation rules for Python code . Code with the same indentation is treated as a block of code, with 3, 4 lines of print statements constituting a block of code (but excluding print on line 5th). If the IF statement evaluates to True, the code block is executed.
    2. Indent please strictly follow Python's customary notation:4 spaces, do not use tab, do not Mix tab and space , otherwise it is easy to cause syntax errors due to indentation.
    3. NOTE: The If statement is followed by an expression, and then with: Represents the code block to begin with.
    4. If you hit the code in a Python interactive environment , also pay special attention to indentation , and exit indentation requires more than one line of return:

when the If statement determines that the result of the expression is True, the IF-contained code block is executed:

use if ... else ... Statement, we can execute an if code block or an else code block, depending on the value of the conditional expression, either True or False. Note: Else there is a ":" later To avoid nesting structures if ... else ..., we can use the if ... Multiple elif ... else ... Structure, write all the rules at once : Special attention: This series of conditional judgment will be judged from top to bottom, if a certain judgment is True, after executing the corresponding code block, the subsequent condition judgment is ignored and no longer executed . want to see more detailed please see http://note.youdao.com/noteshare?id=ddd78caf8d8d195e4c66d24a4fb5f862&sub= eda7f9c87ff7454da80da9f046ee7975

Python's If statement

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.