The 16th lesson in Python Learning--indentation (indentation)

Source: Internet
Author: User

The most distinctive feature of Python is the code that is labeled as a block in indentation.

below we use the IF selection structure example, if followed by the condition, if the condition is true, then execute a block of code that belongs to the if

look first . C the way of language expression

if (i>0) {    x=1;    Y=3;}

if i>0 , we will carry out the two assignment statements that are included in parentheses. The parentheses contain the block operation, which is subordinate to the if

same purpose, in python , this passage is like this.

if i>0:    x=1    y=3

in python , remove the parentheses around the i>0 , remove the semicolon at the end of each statement, and the curly brace of the block disappears. Extra :( colon ), as well as the indentation of the preceding four spaces in the x=1 and y=3 statements, by indenting python recognizes these two statements when they are subordinate to the if. The reason Python is designed to look good and simple for the program

Summarize:

the indentation of the preceding four spaces in the statement indicates an affiliation, andPython cannot be indented

if < conditions 1>:    statementelif < conditions 2>:    statementelif < conditions 3>:    statementElse:    statement

 while i>0:    x=2    y=3 while     x==2:        Print( " Hello ")

The 16th lesson in Python Learning--indentation (indentation)

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.