iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 29
0
Google Developers Machine Learning

Python + 機器學習/深度學習小筆記系列 第 29

[Day - 29]Python+AI從入門到精通(Python基礎編程-循環語句while)

  • 分享至 

  • twitterImage
  •  

在python程序中,除了for循環語句之外,while語句也是十分重要的循環語句。

while循環語句最大的特點是不知道詢還多少次使用它,當不知道語句需要重複多少次時,使用while語句是最好的選擇。

while語句的基本格式:

while condition:
statements

其中,
condition表示循環條件
statements表示執行語句

while循環語句的執行流程圖
https://ithelp.ithome.com.tw/upload/images/20190930/20119675ZVXxSPZOKD.jpg

例子

count=0

while count<10:
    print(count)
    count=count+1  #也可以寫成 count+=1
print('Done.')

上一篇
[Day - 28]Python+AI從入門到精通(Python基礎編程-輸入輸出)
下一篇
[Day - 30]Python+AI從入門到精通(Python基礎編程-函數)
系列文
Python + 機器學習/深度學習小筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言