robylin
    • 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 主題 * type&I/O&operator * conditional statements * loop * container(list,dic, set, tuple) # 責編的話 * 內容先以補充為主,之後再濃縮 * 主要是介紹,可參考reference [TOC] # type&I/O&operator - [ ] 學習目標 * 了解並掌握 Python 中的變數類別和輸入輸出,能夠區分並正確使用不同類型的變數,為程式設計中的**資料處理**和**邏輯運算**打下基礎。 - [ ] 知識點 1. 變數的基本概念 * **什麼是變數?** * **變數如何儲存資料?** 2. 輸入輸出 * `input()` * `print()` 3. Python 的資料類型 * 基本資料型別: * 整數 (int) * 浮點數 (float) * 字串 (str) * 布林值 (bool) 4. 資料型別轉換 * 隱式轉換與顯式轉換 * `int()`、`str()`、`float()` 等函數的使用 5. 變數的宣告與使用 * 命名規則 * 動態型別特性(不需明確宣告型別) * 使用 `type()` 檢查變數的資料型別 6. common operator * "\+\-*/" - 四則運算 * "== !=" - 等於/不等於 * "< >" 小於/大於 * "** //" - 指數/整數除法 # conditional statements - [ ] 學習目標 * 了解並掌握 Python 中最簡單的流程控制「如果」的用法(if...elif...else...),能根據指定條件去做出該條件對應之操作 - [ ] 知識點 1. if條件判斷 * if-elif-else 結構: ```python score = int(input("score: ")) if score >= 90: print('Grade is: A') elif score >= 80: print('Grade is: B') elif score >= 70: print('Grade is: C') elif score >= 60: print('Grade is: D') else: print('Grade is: F') ``` ![image](https://hackmd.io/_uploads/rJ9_ZxUm1e.png) ![image](https://hackmd.io/_uploads/rJNJfx8XJx.png) ![image](https://hackmd.io/_uploads/rkRnWeUXJg.png) 2.縮排(應該標示前面在程式碼中即可) * 縮排錯誤會導致 SyntaxError * 標準(PEP8): `tab`or`4下space` * 二選一,不可混合使用 3.match判斷 * match結構 ```python command = "start" match command: case "start": print("Starting...")#值=start執行此代碼 case "stop": print("Stopping...")#值=stop執行此代碼 case _: print("Unknown command")#非以上2者則執行此代碼 ``` ![image](https://hackmd.io/_uploads/SJg7Ng8Qkl.png) * container(如list、tuple) ```python point = (10,0) match point:#判斷點是原點 or x 軸上的點 or 直接輸出點座標 case (0, 0): print("原點") case (x, 0): print(f"x 軸上的點,x = {x}") case (x, y): print(f"點位於 ({x}, {y})") ``` ![image](https://hackmd.io/_uploads/HyRHte87Jg.png) * 變數的類型 ```python value = 1.1 match value:#判斷value是整數 or 字串 or 都不是 case int(): print("這是一個整數") case str(): print("這是一個字串") case _: #通配符"_"-用於忽略不重要的值或匹配任何情況 print("未知類型") ``` ![image](https://hackmd.io/_uploads/Bk3AKeUXJe.png) * 與 if-elif-else 的對比 * 優點: * 簡潔且更易讀,特別是在多分支邏輯或結構化資料處理時。 * 適用場景:當匹配值是結構化資料、特定類型或多條件時,match 比傳統的 if-elif 更高效 # loop - [ ] 學習目標 * 了解並掌握 Python 中的循環結構(loops),能夠靈活使用迴圈來自動執行重複任務,提升程式的效率與簡潔性。 - [ ] 知識點 1.為什麼要用迴圈 * 透過迴圈,程式可以自動重複執行指令,簡化程式碼、增加效率、方便處理大量資料 2.for迴圈 ```python for i in range(5): print(i, end=" ") ``` ![image](https://hackmd.io/_uploads/rynI_n4XJl.png) 3.while迴圈 ```python i=0 while(i<5): print(i,end=" ") i=i+1 ``` ![image](https://hackmd.io/_uploads/rynI_n4XJl.png) 4. 迴圈控制語法 * `break` * 提前結束迴圈。 * `continue` * 跳過當前迭代,直接進入下一次迭代。 ``` python for i in range(3): print(i,end=" ") if i == 5: break else: print("未中斷,執行此區塊") ``` ![image](https://hackmd.io/_uploads/r1ewQYh4XJe.png) # container(list,dic, set, tuple) - [ ] 學習目標 * 能夠根據需求選擇適合的資料結構,提升程式的效率與可讀性。 - [ ] 知識點 * 清單 (list) ```python= mytuple = ["apple", "banana", "cherry"] ``` * 特性:有序可變(元素可新增、刪除、修改),可包含重複元素。 * 增加元素:`append()`、`insert()`、`extend()` * 刪除元素:`remove()`、`pop()` * 排序:`sort()` * 長度:`len()` * 存取元素:使用索引值存取元素。 * 切割操作:`list[start:end:step]` * 使用場景:儲存有序資料且需頻繁修改。 * 元組 (tuple) ```python= mytuple = ("apple", "banana", "cherry") ``` * 特性:有序不可變(元素不可修改),包含重複元素。 * 使用場景:儲存不需改動的固定資料。 * 集合 (set) ```python= mytuple = {"apple", "banana", "cherry"} ``` * 無序,元素唯一,可變(元素可新增或刪除)。 * 高速存取 - 平均O(1)的查找時間 * 常見操作: * 新增與刪除:`add()`、`remove()` * 集合運算:`交集(&)`、`聯集(|)`、`差集(-)` * 使用場景:過濾重複資料或集合操作。 * 字典 (dict) ```python= thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } ``` * 無序(Python 3.7 中有插入順序),key唯一,以key-value對的形式存儲資料。 * 常見操作: * 增加/修改:`dict[key] = value` * 刪除:`del dict[key]、pop()` * 遍歷:`for key, value in dict.items()` * 使用場景:基於key快速查找資料,計算元素的出現次數。 * 資料結構的比較與選擇 * 何時使用 List vs Tuple ? * 如果需要**有序、可修改且允許重複元素**的資料集合,選擇List。 * 如果需要**有序但不可修改**的資料集合,選擇Tuple * 何時選擇 Dict 而非 Set? * 如果需要根據**特定鍵快速查找和操作資料**,選擇Dictionary。 * 如果需要**唯一元素且不關心順序**,以及對集合運算有需求,選擇Set。 # reference * 2022資訊之芽 py 語法班 [https://sprout.tw/py2022/slides](https://) * 為你自己學 PYTHON https://pythonbook.cc/chapters/basic/variable * Python 3.13.0 Documentation https://docs.python.org/3/ * PEP-8 Style Guide https://peps.python.org/pep-0008/ * Python 基礎筆記:可變動的(mutable)與不可變動的(immutable) https://medium.com/@oange6214/python-%E5%9F%BA%E7%A4%8E%E7%AD%86%E8%A8%98-%E5%8F%AF%E8%AE%8A%E5%8B%95%E7%9A%84-mutable-%E8%88%87%E4%B8%8D%E5%8F%AF%E8%AE%8A%E5%8B%95%E7%9A%84-immutble-54f1b7a6899

    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