pythonwhile用法
發布時間: 2025-10-13 04:26:03
❶ pythonwhile循環的用法是什麼
python while循環語句:
while 判斷條件(condition):
執行語句(statements)……
執行語句可以是單個語句或語句塊。判斷條件可以是任何錶達式,任何非零、或非空(null)的值均為true。
當判斷條件假 false 時,循環結束。
實例:
#!/usr/bin/python
count = 0
while (count < 9):
print 'The count is:', count
count = count + 1
print "Good bye!"
運行實例 »
以上代碼執行輸出結果:
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!
熱點內容