iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 24
0
自我挑戰組

Python 自學歷程分享系列 第 24

for迴圈-2

在上一篇中有提到For並不只能放入range(),for能支援的東西很多,只要是有支援__iter__()方法的物件,都能利用for,像是List跟字串
https://ithelp.ithome.com.tw/upload/images/20181027/20112140rPbw8gZKFb.png
https://ithelp.ithome.com.tw/upload/images/20181027/201121403u26qQ89sc.png
在for陳述句後面我們也可以加入else陳述句,可以搭配關鍵字「break」使用,只要使用break中途跳出迴圈的話,就不會執行else的內容,我們用簡單的「找質數」來舉例:
https://ithelp.ithome.com.tw/upload/images/20181027/20112140nY1DL89TCu.png


上一篇
for迴圈語法
下一篇
while迴圈
系列文
Python 自學歷程分享30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言