ython Loops

WBOY
Libérer: 2024-07-25 00:04:32
original
441 人浏览过

ython Loops

Python Loops
Python has two primitive loop commands:

*while loops
for loops *

The while Loop:

With the while loop we can execute a set of statements as long as a condition is true.

`i = 1
while i < 6:
print(i)
i += 1

Output :

1
2
3
4
5
`
For loop:

A "For" Loop is used to repeat a specific block of code a known number of times

fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
Output :
apple
banana
cherry

Type of Loops:

For Loop. A for loop in Python is used to iterate over a sequence (list, tuple, set, dictionary, and string). Flowchart: .....

**While Loop. **The while loop is used to execute a set of statements as long as a condition is true. ...

**Nested Loop. **If a loop exists inside the body of another loop, it is called a nested loop.

以上是ython Loops的详细内容。更多信息请关注PHP中文网其他相关文章!

source:dev.to
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!