iT邦幫忙

0

PYTHON 學習筆記 0010 (休假也要認真學習!!!!!)

  • 分享至 

  • xImage
  •  

for 迴圈

# for 迴圈
# for 變數 in 字串OR列表
#     要重複執行的程式碼
for what in "JODER":
    print(what)
for num in [1,11,2,22,33,44,1]:
    print(num)
# for 變數 in range(次數) EX:0~11 (12次)
for num in range(12):
    print(num)

for num in [4,5,6,7,8,9,10]:
    print(num)
for num in range(4,11):
    print(num)

https://ithelp.ithome.com.tw/upload/images/20221229/20156136tPj2hX2fSC.jpg

https://ithelp.ithome.com.tw/upload/images/20221229/201561363lNFgrUL3F.jpg

https://ithelp.ithome.com.tw/upload/images/20221229/20156136X7MAz6Kk9u.jpg

https://ithelp.ithome.com.tw/upload/images/20221229/20156136fOJbN00GxF.jpg

次方函數 pow=(基數,次方數)

pow(3,4)


def power(base_num,pow_num):
    result = base_num
    for index in range(pow_num-1):
        result = result * base_num
    return result
print(power(3,4))
def power(base_num,pow_num):
    result =1
    for index in range(pow_num):
        result = result * base_num
    return result
print(power(3,4))

https://ithelp.ithome.com.tw/upload/images/20221229/201561367sRT7ZiJS7.jpg

https://ithelp.ithome.com.tw/upload/images/20221229/20156136kqdRDJi7yd.jpg


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言