新聞詳情
python ——2.2 while循環(huán)語句發(fā)表時間:2022-05-09 16:18 Python 編程中 while 語句用于循環(huán)執(zhí)行程序,即在某條件下,循環(huán)執(zhí)行某段程序,以處理需要重復處理的相同任務。其基本形式為: while 判斷條件(condition): 執(zhí)行語句(statements)…… 執(zhí)行語句可以是單個語句或語句塊。判斷條件可以是任何表達式,任何非零、或非空(null)的值均為true。 當判斷條件假 false 時,循環(huán)結束。 執(zhí)行流程圖如下: 實例 #!/usr/bin/python count = 0 while (count < 9): print 'The count is:', count count = count + 1 print "Good bye!" 運行實例 ? 以上代碼執(zhí)行輸出結果: 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!
文章分類:
信息技術-教學資源
|