Python Study Notes (4)

Source: Internet
Author: User

Python Study Notes (4)
While · general syntax

While control condition: execution statement
The statement is executed until the control condition is false ".
· Infinite Loop
While True: execution statement
Programs that can be executed continuously are very dangerous. We will only see them on certain occasions. For example, some servers need to monitor whether a client is connected at any time. These clients may send requests to the server at any time, so the server's listener must be on standby.
· Counting cycle
This is the most common statement. It uses counters to determine when the loop ends.
Count = 0; while count <10: print count + = 1
The range () function requires one, two, or three parameters.
Range (start, end, step)
If step is 1, it can be omitted. There are two parameters.
If there is only one parameter, start starts counting from 0 by default.
The len () function returns the number of elements in a sequence.
For Loop
Movies = ["Avata", "Xman", "Titannic", "The Dark Knight Rises", "Jurassic Park", "Dances with Wolves"] for movie in movies: print moviefor item in range (len (movies): print item, ":", movies [item]

Like the C language, break breaks out of this loop, while continue does not continue to execute the following code.
For I in range (10): if I = 6: break print I, for I in range (10): if I = 6: continue print I,

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.