0:", etc."/> 0:", etc.">

Home  >  Article  >  Backend Development  >  How to write python loop 10 times

How to write python loop 10 times

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-26 17:36:4031599browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn