Daniel Chen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2021資訊之芽北區Python ## **課程資訊**https://tw-csie-sprout.github.io/py2021/#!index.md ## [匿名提問](https://www.sli.do)(5/9)密碼:835029 ## [大作業說明](https://hackmd.io/J8l8vuQKSqSBpXJidpM0sA?view) ### 開發環境: 1.Anaconda 一堆套件 2.jupyter notebook 測試程式的好工具 先裝了再說 ### 基礎語法: 1.輸出 print(x) print(x, y, sep= , end= ) 連續輸出 (sep:中間用什麼隔開 預設為空格 end:最後再輸出什麼 預設為換行) 2.跳脫字元 \" 輸出" \' 輸出' \n 換行 \t tab \b backspace 3.type(x) 查看x的資料型態 4.a, b = b, a a b 互換 5.輸入 x = input(A) 輸出A,再讓你輸入x的值 input().split() 連續輸入(split括號內代表中間以什麼隔開 預設為空格) 6.help(x) 顯示x的說明 ### 比較運算子: 1.>、< 2.== 等於 3.>=、<= 4.!= 不等於 ### 資料型態: 1.int integer整數 2.float 浮點數 3.bool boolean布林值 True/False 4.str string字串 5.dict dictionary ### 運算子: 1.+ 加 2.- 減 3.* 乘 4./ 除 5.** 次方 6.// 求商 7.% 求餘數 ### 形別轉換: A(x) 把x的型別轉成型別A ## 邏輯 ### 邏輯運算子: 1.not A = True not A = False 2.and True and True = True others = False 3.or False or False = False others = True 4.xor A xor B AB相同 = True AB不同 = False ### if if 條件句 : 內容(要縮排) elif 條件句 : 內容(要縮排) else : 內容(要縮排) 條件句太長可以用"\"換行 ### Boolean: 如果條件句不是BOLEAN 會被強制型態轉換成BOOLEAN 簡單來說 把那個變數以布林處理 ### 狄摩根定理: not(A and/or B) = (not A) or/and (not B) ### 迴圈 #### while: while 條件句: 內容 else :(條件句為非時執行) 內容 break:跳出迴圈 continue:跳過這一次(直接回到條件句) #### for: for i in range(起始值, 做到小於多少): 內容 else: (完整跑完後執行,有break就不會執行) 內容 break:跳出迴圈 continue:跳過這一次(i自動+1) ### list: len(list):list長度 list[i]:存取第幾個 (0<=i<長度, -長度<i<=-1) #### add: list.append(obj):在後面加入obj list.insert(index, obj):在index前面加入obj list.extend(list2):在後面加入list2 #### delete: list.pop(index):把list[index]拔掉並遞補 list.remove(obj):把第一個出現的obj拔掉並遞補 list.clear():清空 #### sort: list.sort():由小到大排序 list.reverse():反轉 list.sort(reverse=True):由大到小排序 #### traversal: for i in list: 直接遊歷value,不能改值 for i in range(len(list)): 遊歷index,可以改值 for i, j in enumerate(list): 同時遊歷兩者 #### function max(a) min(a) sum(a) map(function,a) 把A裡面的每個元素都傳進函式一次然後回傳一次新的list sorted(a):回傳一個排序好的list,不會影響原本的list #### copy list.copy() #### slicing切片 list[start:end:step] start:起點 end:終點(不包含) step:每次加幾 ### string #### 運算 +:連起來 *:重複幾遍 ==:等於 !=:不等於 比大小:比字典序 #### Function(都不會更改原本的字串 而是回傳一個新字串) list.replace():取代 不會遞回取代(只跑一次) 可以重複跑很多次 list.strip():去除頭尾的空白或指定的字元 list.find(目標, 起點預設0, 終點預設長度):尋找並回傳第一個找到的位置 list.split("分割處"):分割字串 list.join("a", "b", "c"):把a,b,c用list黏起來 list.upper():變大寫 list.lower():變小寫 list.isdigit():判斷是否是數字 #### format string "{}*{}={}".format(i, j, i*j) ### dictionary 一種資料型態 dictionary:key=>value(list:index=>value) 用大括號包起來 ### function def函數名稱(parameter參數): 函數內容 函數名稱(argument引數):呼叫該函數 #### parameter&arguments 變數不會更改原本的值,但如果型態是 list, dict, set 等,則會改到原本的值 #### 回傳值(return) return 之後 function 就會終止,後面的東西都不會執行 ### Import 直接利用別人寫好的程式碼 大型檔案間直接聯繫的橋樑 #### 使用方法 import ___ :直接導入 import ___ as ___:自訂名稱導入 from ___ import ___:導入一特定函式 from ___ import:導入(能直接使用,不須加.在後面)(不建議使用) #### 常用模組 math numpy pandas matplotiib sys #### 慣例 import numpy as np import pandas as pd import matplotlib.pyplot as plt import pygame as pg #### math 相關 gcd():最大公因數 ceil()/floor():上下高斯 pow()/sqrt():次方 平方根 log(x)/exp/log2(x):對數 sin(x)/cos(x)arccos(x)/tanh(x):三角函數 反三角函數 雙曲函數 pi/e:常數 factorial(n):階乘 #### string 相關 ascii_lowercase:小寫 ascii_uppercase:大寫 digits:數字 punctuation:標點符號 #### random random:<0<=1的浮點數 uniform(a, b):<a<b之間的浮點數 randint(a, b):<a<b之間的整數 choice(x):從list x中挑一個 shuffle(x):重排list x中的元素 #### os getcwd() : 取得當前目錄 listdir( ) : 列出目錄底下的檔案 path.join( ) : 組合成完整路徑名 path.exists( ) : 檢查是否存在 remove( ) : 刪除檔案 #### sys argv:命令列的參數(list) version:python版本 platform:操作系統平台名稱 stdout:標準輸出 #### time time():從1970/1/1 00:00到現在的秒數 sleep(s):暫停幾秒 localtime():當地時間 asctime():格式化時間 #### datetime datetime.now():現在時間 date.today():今天日期 timedelta(時間=時間單位):時間間隔 #### 自製 1.寫一個py檔 2.在另一個py檔中import它(兩檔案須在同一路徑中) #### file I/O input:打開檔案時 output:儲存檔案時 #### 檔案 文字檔:html,txt 二進位檔:png,zip,docx #### 路徑 絕對路徑:從最上面目錄開始 相對路徑:從自身位置出發 #### 開檔 ### 開檔模式 r:只能讀 w:只能寫 a:寫在最後面 r+: w+: a+: #### 關檔 關檔之前檔案不會被寫入(可用flush解決) 易佔記憶體空間 #### 常用寫法 with open([file_name],'r/a/w') as [file_object]:

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully