Python entry loop for loop (note 2-1)

There are two kinds of loops in Python, like C++ and Java: for loops and while loops

Introduce the for loop here.
For example:
in C++ and Java

for( int i = 0 ; i < 10 ; i++)
{
循环体
}

/* means ten cycles. */

It should be written
like this in Python : there is no such thing as i<10 in Python, so we need to use the rouge() function to determine the number of loops.
Here we only range () function to solve the problem of cycles , more detailed range () function description, please click

range( n, m) function // n, m are all and can only be integer functions.
According to the figure below, the range() function returns a similar list, or tuple, which is actually an object type from n to m- 1. At this point, the number of cycles is solved.

The difference between arrays (lists, tuples, dictionaries) in Python, please click here.
Insert picture description here
Every time you complete a loop, i will move backward by one position, so there is no need to operate on i

 for i in range(0,10)://i为无意义的变量名可更改
    	print(i)
    	......
    	......

**/\*循环体的每行,不论是自动添加还是手打的,行首必须要有一个缩进,\*/**

Insert picture description here
The for loop can also be used
Insert picture description here
in this way. The code implementation in PyCharm and the code in Python.exe (IDE) are still different.
If you don’t understand the content of this article, you can leave a question in the comments and make progress together.

Guess you like

Origin blog.csdn.net/qq_43228135/article/details/86755731