Python branch Loop

Source: Internet
Author: User

a python knowledge point
1. Variables (tags):
A (variable name) = ' String ' or number (shaping and floating point) A is equivalent to the tag of the variable name
such as: a = ' your sister ' is equivalent to the string ' Your sister ' added a a tag or a name a
Note the point:
1. The variable name is a letter, a number, an underscore, but not a number begins to name, see its name the meaning
2. Semicolons must be in English format and do not have semicolons
2. Branching and follow -up:
1. Branch:
If condition: #条件成立执行分支1
Branch 1
else: #条件不成立执行分支2
Branch 2
_____________
If condition: #条件成立执行分支1
Branch 1
Elif Condition: #条件成立执行分支2
Branch 2
..........
else: #条件不成立执行分支n
Branch N
____________
2 Cycles:

1.for CycleThe for iteration variable in target such as: For I in range (0,10,1) I is the adder, each time +1,range (0,10,1) represents an integer from 0 to 9 1 between each two digits, Range (start number, end Count minus 1, interval between every two digits)2.while CycleWhile condition: the process of repeating in the case of a bad body, in which condition is right3. Cycle Control                        1.break: Jump out of the current loop body                                count = 0    #计算循环了多少次, initially 0 times                                While true:                                       print (' hello ')   #反复执行的语句                                    &nbsP;   count +=1    #每循环一次count的值加1, count = shorthand for count+1                                        if count = =:   # Determine if the loop is 100 times, and if it is, execute the IF statement below                                               break               #跳出这个循环体, not on the bad                          —————————————————————————— ——————                      &Nbsp;    for i in range (0,100,1):                                  print (' hello ')     #反复执行的语句                                   if count = =: #判断是否循环了100次, if it is, execute the IF statement below                                   break #跳出这个循环体, not bad                   2 equivalent                         2. Continue: Jumps out of the current loop into the next loop                            count = 0 #计算循环了多少次, initially 0 times                             while true:    #条件为True, always true                                   print (' hello ') #反复执行的语句                                   count +=1 #每循环一次count的值加1, count = shorthand for count+1                                   if count = =:    #判断是否循环了100次, if so, execute the IF statement below                                   continue        #跳出第100次循环, go to the next bad                        3. Attention PointsA. Statement to shelf write, do not have a space B. After the condition, you must add a semicolon in English format: C. Branches and loops the statements following the criteria must be indented,Indent inIs the soul of the Python language D. #字符后面的内容表示注释说明, there is a way to "annotate content"

Python branch Loop

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.