Python for loop (1), pythonfor Loop

Source: Internet
Author: User

Python for loop (1), pythonfor Loop

For a beginner, The for loop may crash many people, because the python for loop found on the Internet does not have a detailed description of the for Loop conditions and what is defined after the for loop. First, let's give a common example.

For I in range (1, 10 ):

Print I

The above two codes are used to print 1 to 9 on the screen. Here we will not introduce the range function. You can go to Baidu to check it. Or I will introduce it later.

Here I is a variable defined by myself. The range (1, 10) after the variable in is a condition. The process from the execution of this loop to the execution of the execution is to assign a value to the I in the range first, and then print out the I-assigned items in the loop. After printing, return to for to check whether the loop is complete. after the loop is completed, the second number generated by range is assigned to I and then printed continuously until range does not generate a number. I used a lot

For I in 'hello, world ':

Print I

This line of code prints hello and world to the screen one by one. In this case, for is followed by defining an I variable. When the characters in the hello and world strings are assigned to I one by one, they are printed to the screen through print. The for loop of python is just a summary here. In the future, I will talk about more about the for loop.

You are also welcome to point out the shortcomings in the comment area. I will improve it slowly.

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.