Python3 Condition Control if

Source: Internet
Author: User

A python conditional statement determines which part of the code executes by executing the result of one or more statements (true or false).

If statement

The general form of the IF statement is as follows:

If condition 1:

Statement 1

Elif Condition 2:

Statement 2

Else

Statement 3

The meaning is:

If condition 1 is true, statement 1 is executed;

If condition 1 is false, the condition 2 is judged;

If condition 2 is true, statement 2 is executed;

If condition 2 is false, statement 3 is executed.

Attention:

1. Each condition is followed by a colon (:), which indicates the next statement to be executed after satisfying the condition;

2. Use indentation to divide the statement block, the same level of statements using the same indentation.

The following is a simple example:

VAR1 = 100
If var1:
Print ("1-if expression condition is true")
Print (VAR1)

VAR2 = 0
If var2:
Print ("2-if expression condition is true")
Print (VAR2)
Print ("Good bye!")

The results of the implementation are as follows:

1-if expression condition is true
100
Good bye!

As you can see from the results, the statement within the corresponding if is not executed because the value of VAR2 is 0.

Python3 Condition Control if

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.