ython Loops

WBOY
Freigeben: 2024-07-25 00:04:32
Original
440 人浏览过

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中文网其他相关文章!

Quelle:dev.to
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!