招生電話:0816-8119777
新聞詳情

python ——2.2  while循環(huán)語句

發(fā)表時(shí)間:2022-05-09 16:18

Python 編程中 while 語句用于循環(huán)執(zhí)行程序,即在某條件下,循環(huán)執(zhí)行某段程序,以處理需要重復(fù)處理的相同任務(wù)。其基本形式為:


while 判斷條件(condition):

    執(zhí)行語句(statements)……

執(zhí)行語句可以是單個(gè)語句或語句塊。判斷條件可以是任何表達(dá)式,任何非零、或非空(null)的值均為true。


當(dāng)判斷條件假 false 時(shí),循環(huán)結(jié)束。


執(zhí)行流程圖如下:


實(shí)例

#!/usr/bin/python


count = 0

while (count < 9):

   print 'The count is:', count

   count = count + 1


print "Good bye!"


運(yùn)行實(shí)例 ?

以上代碼執(zhí)行輸出結(jié)果:


The count is: 0

The count is: 1

The count is: 2

The count is: 3

The count is: 4

The count is: 5

The count is: 6

The count is: 7

The count is: 8

Good bye!


辦公室/傳真:0816-8119666
招生辦:0816- 8119777
地址:四川省綿陽市園藝山教育園區(qū)
郵箱:mzsyxxzsb@sina.com
官方服務(wù)號(hào)
官方訂閱號(hào)
官方視頻號(hào)
官方抖音號(hào)
官方微博號(hào)
北京英才苑
四川省電化教育館
綿陽教育體育館
綿陽招生考試網(wǎng)
友情鏈接: