Python Learning Notes (6)--for...in &while

Source: Internet
Author: User

for x in ...A loop is a statement that puts each element into a variable and x then executes the indented block .

Note: Formatting in Python also acts as a syntax rule, and indenting a block is an example

summation problem, comparison and similarity 1/
Sum=0 forXinch[1,2,3,4,5,6,7,8,9,Ten]: Sum=sum+The xprint (sum) #此行无缩进, which indicates that the print command is not executed until the FOR Loop statement is finished, that the so-called "indent block" is the rule of the Python syntax, that the indentation is part of the For loop, and that no indentation jumps out of the For loop (or jumps out of the previous syntax) >>> -----------------------------2/
Sum=0 forXinch[1,2,3,4,5,6,7,8,9,Ten]: Sum=sum+With the x print (sum) #此处print有和上一行sum一样的缩进, the Py considers the line to be part of the indent block, and then executes the syntax rule, which loops 10 times with the sum of the print. >>>1 3 6 Ten the + - $ $ -

Python "code writing format" equivalent "syntax format", indentation and other habits can not be used, such as HTML and other grammar in order to look at the white space, tab and other habits will be strictly forbidden, perhaps one of the achievements of Python is to write code is very regular, not too many personal randomness.

Python Learning Notes (6)--for...in &while

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.