python中循环结构分有,python常见循环结构有哪些
1、for…in…
該格式在python中是最為常見的一種格式,使用極為廣泛。格式:for?參數?in?循環體:
pass
在上面的格式中,有很多內容可以作為循環體,比如元組、列表、字符串等等。只要能穿越循環,就可以作為循環體存在。
其中參數主要用來存儲每個循環體發送的單個元素,從而實現循環功能。在實踐中,它經常與if判斷語句結合使用。#input
str_01?=?'時間都去哪了!!!'
for?i?in?str_01:
print(i)
#output
時
間
都
去
哪
了
!
!
!
2、while
while循環和for…in…循環的不同之處在于,while要先將循環變量初始化或者直接使用while True 這種死循環形式。格式:i?=?0
while?i?>=10:
pass
i?+=1#input
while?True:
print('hello?world!!!__hello?python!!!')
#output
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
hello?world!!!__hello?python!!!
.
.
.
.
.
.
以上就是python中2種常見循環結構,希望能對大家有所幫助。更多Python學習指路:
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的python中循环结构分有,python常见循环结构有哪些的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql三种引擎_MySQL常见的三种
- 下一篇: Redis Scan 命令