ython Loops

WBOY
Lepaskan: 2024-07-25 00:04:32
asal
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中文网其他相关文章!

sumber:dev.to
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!