Python Logic and loop mode

Source: Internet
Author: User

1. Grammar

If Condition:

Code 1

Code 2

Code 3

(The same distance code as the indentation is the same code block, the code runs from top to bottom, and when a condition is not true, the next condition is run)

Syntax format:

If:

Code 1

Elif:

Code 1

else:

Code 1

If nesting (when an if condition is established, enter the next logical judgment in this condition)

While loop syntax, While loop is also called a conditional loop.

While condition:

Code1

While + broken : break means to terminate the loop of the current layer and execute other code

While True:

Print1

Print2

Break

While + continue: continue means to terminate the cycle and go directly to the next loop

Coutinue do not add the code that executes in the last step of the loop body, meaningless.

While+tag: When tag=false all exits

While+else: The terminal will not display until after the program has finished executing.

the Process Control For loop: Remove multiple values from a type

Default count mode

Step Size The default is 1, set to 2 when 1,3

Python Logic and loop mode

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.