程式語言提供了各種控制結(jié)構(gòu),允許更複雜的執(zhí)行路徑。循環(huán)語句允許我們執(zhí)行一個(gè)語句或語句組多次
Python 循環(huán)語句 語法
Python提供了for迴圈和while迴圈(在Python中沒有do..while迴圈)
Python 循環(huán)語句 範(fàn)例
while循環(huán)語句
#!/usr/bin/python ?count?=?0while?(count?<?9):???print?'The?count?is:',?count ???count?=?count?+?1 print?"Good?bye!"
for?循環(huán)語句
#!/usr/ bin/python#?-*-?coding:?UTF-8?-*- ?for?letter?in?'Python':?????#?第一個(gè)實(shí)例 ???print?'當(dāng)前字母?:',?letter ?fruits?=?['banana',?'apple',??'mango']for?fruit?in?fruits:????????#?第二個(gè)實(shí)例 ???print?'當(dāng)前水果?:',?fruit ?print?"Good?bye!"