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.