iT邦幫忙

2021 iThome 鐵人賽

DAY 16
0
Modern Web

基礎python,讓你學點東西系列 第 16

[Day16]-應用模組

  • 建立自己的函數與類別模組,兩者應用都差不多,所以一起講
  1. 先建立自己的函數與類別
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644DAZoIGVtgi.png
  2. 導入模組
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644nJ8FIaBjQF.png
  3. 結果
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644RigEOex4h0.png
  • 隨機random模組
    使用前要先import random
  1. Randint(x,y) 從x到y(含)之間的隨機整數
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644LAVFz3A2ml.png
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644da7GMnI7f0.png
  2. Uniform(x,y) 從x到y(不含)之間的隨機浮點數
    Random() 從0到1(不含)之間的浮點浮點數
    https://ithelp.ithome.com.tw/upload/images/20210928/2014064435xirxI71h.png
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644zvbuOfmNyv.png
  3. Shuffle(串列) 串列裡的元素重新排列
    Sample(串列,n) 產生n個串列元素
    https://ithelp.ithome.com.tw/upload/images/20210928/20140644kR4YaaOsro.png
    https://ithelp.ithome.com.tw/upload/images/20210928/201406447LssqVjQp7.png

上一篇
[Day15]-類別2
下一篇
[Day17]-應用模組2
系列文
基礎python,讓你學點東西30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言