Home > Backend Development > Python Tutorial > How to write python loop 10 times

How to write python loop 10 times

爱喝马黛茶的安东尼
Release: 2019-06-26 17:36:40
Original
31717 people have browsed it

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)
Copy after login

Example:

for i in range(10):
    print("php.cn")
Copy after login

Output result:

php.cn
php.cn
php.cn
php.cn
php.cn
php.cn
php.cn
php.cn
php.cn
php.cn
Copy after login
Copy after login

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
Copy after login

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
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template