0:", etc."/> 0:", etc.">
Home >Backend Development >Python Tutorial >How to write python loop 10 times
Python for loop can iterate over any sequence of items, such as a list or a string.
Grammar:
The syntax format of for loop is as follows:
for iterating_var in sequence: statements(s)
Example:
for i in range(10): print("php.cn")
Output result:
php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn
Related recommendations: "Python Video Tutorial"
The while statement in Python programming is used to execute programs in a loop, that is, under certain conditions, a certain program is executed in a loop to handle the need to repeat handle the same tasks. Its basic form is:
while Judgment condition:
Execution statement...
The execution statement can be a single statement or a statement block. The judgment condition can be any expression, and any non-zero or non-null value is true.
When the judgment condition is false, the loop ends.
a = 10 while a>0: print ('php.cn') a -=1
The results are as follows:
php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn php.cn
The above is the detailed content of How to write python loop 10 times. For more information, please follow other related articles on the PHP Chinese website!