Python next day -- if statement, pythonif statement

Source: Internet
Author: User

Python next day -- if statement, pythonif statement

If statement

Computers, also known as computers, mean that computers can respond differently (Execute Code) to changes in the environment conditions (that is, expession) like the human brain) the if statement is used to control the computer to implement this function.

Syntax:

1. Single Branch, single condition judgment

If expression:

Expr_true_suite

Note: expression is the true Execution Code expr_true_sutie.

 

2. Single Branch, multiple condition judgment

If not active or over_itme> = 10:

Print ('Warning: service is over ')

 

3. if and else

If expression:

Expr_true_suite

Else:

Expr_false_suite

 

4. multi-branch if + elif + else

If expression1:

Expr1_true_suite

Elif expression2:

Expr2_true_suite

Elif expression3:

Expr3_true_suite

Else:

Expr_false_suite

Summary:

1. if the expression returns True after the if statement is executed, the sub-code block is executed, and the if statement ends at this end. Otherwise, the next branch is used for judgment until one of the branches is satisfied, and if

2. expression can introduce operators: not, and, or, is, is not

3. Multiple expressions should be included in parentheses to enhance readability

4. if is consistent with the else indentation level, it indicates a pair

5. Both elif and else are optional.

6. A single if statement can have at most one else, but multiple elif statements can exist.

7. else indicates the end of if judgment

8. expession can be a Boolean expression (for example, x> 1, x is not None), but also a single standard Object (for example, x = 1; if x: print ('OK '))

# A = 1 # if a: # print ('OK') # B = 1 # if B-1: # print ('OK') # if judgment can also use the expression method

 

9. All standard objects can be used for Boolean testing and can be compared between objects of the same type. Each object has a Boolean value of True or False. The Boolean value of Null object, any number with zero value, or Null object None is False.

 

The Boolean value of the following objects is False.

 

To be completed...

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.