"Python" Getting Started (iii)

Source: Internet
Author: User

For loop

for I in Range (): #注意冒号 The default from 0 or from the specified number to the previous number of the given number, the increment is decremented.

For loop provides automatic initialization of variables

 forIinchRange (10):    Print(I,end =' ')Print() forIinchRange (5,10):    Print(I,end =' ')Print() forIinchRange (10,0,-1):    Print(I, end =' ')Print()
>>> ================================ RESTART ================================>>>

While loop:

Need to initialize itself, can contain an ELSE statement block

i = 0 while I <:    print"    )= i + 1print ()

When the number of cycles in advance is indeterminate, the For loop cannot be used such as:

# donesum.pytotal == input ('input a number or "do":')while  'done':    = total+ int (s)    = input (' input a number or "done": ' )print(' + str (total))

Break #跳出循环

continue #进入下一次循环 less use better

Multilayer loops:

#timestable.py forRowinchRange (1,10):     forColinchRange (1,10): Prod= row *ColifProd < 10:            Print(' ', end ="')        Print(Row * col," ", end ="')    Print()
>>> ================================ RESTART ================================>>>  1   2   3   4   5   6   7   8   9   2   4   6   8  ten  18   3   6   9  (   4   8)  20  5,   6, and ten.  7  off in a-si From  8 to   9  in all.  72.  

"Python" Getting Started (iii)

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.