JasonLiu
    • 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
    • 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 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: slide --- <style> html, body, .ui-content { background-color: #333; color: #ddd; } .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { color: #ddd; } .markdown-body h1, .markdown-body h2 { border-bottom-color: #ffffff69; } .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { color: #fff; } .markdown-body img { background-color: transparent; } .ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a { color: white; border-left: 2px solid white; } .expand-toggle:hover, .expand-toggle:focus, .back-to-top:hover, .back-to-top:focus, .go-to-bottom:hover, .go-to-bottom:focus { color: white; } .ui-toc-dropdown { background-color: #333; } .ui-toc-label.btn { background-color: #191919; color: white; } .ui-toc-dropdown .nav>li>a:focus, .ui-toc-dropdown .nav>li>a:hover { color: white; border-left: 1px solid white; } .markdown-body blockquote { color: #bcbcbc; } .markdown-body table tr { background-color: #5f5f5f; } .markdown-body table tr:nth-child(2n) { background-color: #4f4f4f; } .markdown-body code, .markdown-body tt { color: #eee; background-color: rgba(230, 230, 230, 0.36); } a, .open-files-container li.selected a { color: #5EB7E0; } </style> <!-- slide start --> # Python Tutorial 🐍 ## Chapter 0 --- ## 📍 `GMJH` #### ⏱ `2023/07/10` ~ `2023/07/13` ---- ## Basic Topic - syntax - containers - class - function - module ---- ## Labs - console program - online judge ---- ## Advances Topic - data visualization - web crawler - web server --- # Before we start ... ---- ## Slido - **線上匿名提問** - 問都問 🫵 - [present link](https://wall.sli.do/event/593m6SKUqgmJT87DYnZNX4?section=554b011b-ff73-4167-b206-60c4043145f6) - [admin link](https://admin.sli.do/event/593m6SKUqgmJT87DYnZNX4/polls) ---- ## 1. About me ## 2. Tools ## 3. Warm up --- # About me 👋 ---- ## Jason ---- ### 成大資工 大一 - NCKU CSIE - 全國大專電腦軟體設計競賽 - GDSC - 架系統 - 打工仔 - ~~拔草~~ ---- ### 武陵高中 - WLSH - 資訊社社長 - 資訊學科能力競賽 - 高三開始搞開發 - ~~打工仔~~ ---- ### GMJH - 物理老師是 PH 💯 - 完全沒碰過 code ---- ### 我碰過什麼 - Competitive Programming - Frontend - Backend - CTF (web security) - Git workflow - Linux ---- **問都問** 🙌 --- # Tools ⚙️ ---- ## Development Setup 設定我們的開發環境! - VSCode - IDE (整合開發環境) - https://code.visualstudio.com/download - Python - https://www.python.org/downloads/ [安裝教學 🔗](https://hackmd.io/@smallshawn95/vscode_write_py) ---- ## Replit - Online IDE - ( 如果剛剛有成功弄好環境的可以不用 ![](https://hackmd.io/_uploads/Syc6WS_F3.png) ---- ## zerojudge - 全台最知名的 Online Judge - 所有初學者應該都要來寫過! - https://zerojudge.tw/ - 先註冊一下 --- # Warm up 🔥 ---- ## Kahoot [Warm up 🧠](https://create.kahoot.it/my-library/kahoots/9c573301-540f-4546-9b3e-c9a4d1adc942) --- # About Python ---- ## Features ---- ### 語法簡單 好上手(很口語化) ```python! print("Hello World!") a = 1 bucket = [] ``` ---- ### 很多第三方函式庫 - ![](https://hackmd.io/_uploads/ryKU6W_K3.png) - **DRY** principle - **D**on't **r**epeat **y**ourself ---- ### 熱門 packages - AI : - NP , PD , TF , Keras , Pytorch - Web : - Flask , FastAPI , Django ---- ### 熱門 packages (AI) ![](https://hackmd.io/_uploads/H1vSC-dt2.png) ---- ### 熱門 packages (Web) ![](https://hackmd.io/_uploads/S1k2gf_tn.png) ---- ### 執行速度 ? ![](https://hackmd.io/_uploads/r1Yv1GuK2.png) ---- ### 執行速度 其實不快! 應該說是**非常慢** 🐢 ---- ### 熱門程度 {%youtube GVmeP21x3iM%} https://youtu.be/GVmeP21x3iM --- # Summary of Python ---- ## Pros - 語法簡潔 - 快速開發 - 大量第三方套件 - 廣大社群、資源 - 跨平台 ---- ## Cons - 執行速度慢 - 無記憶體控管 ---- 無論如何 每個語言都有優缺點和適用的場域 **Python** 仍是目前的主流語言 ✅ --- # Python syntax --- ## comment ---- ## comment 在寫任何一行 code 之前 先學會要怎麼寫註解! ~~不然寫完過三天就看不懂了~~ ---- ## single line comment ```python= print("Hello world!") # 輸出 Hello world! , 雙引號不會跟著輸出 , 我寫的第一行 code # 第二行 ``` ---- ## multiple line comment ```python= print("Hello world!") ''' 會輸出: Hello world! 雙引號不會跟著輸出 這是我寫的第一行 code 空了好多行,再一行 ''' ``` --- ## stdout ---- ## Output Example ```python! print("This is an output with newline") ``` ( 預設就會換行 ) ---- ## Print with different data type - 不只能輸出「字串」 ```python! print(3.14) print(111) print(False) ``` ---- ## Print multiple variables - 可以用 `,` 分開要輸出的東西 ```python! print("Pi =",3.14) ``` ( 預設會用空白隔開 ) ---- ## Customize end char - 如果我不想要結尾換行呢? ```python! print("End with empty string.",end="") ``` - 可以使用 `end="你想要的結尾"` ---- ## Customize separator - 如果我不想要用空白分隔呢? ```python! print(1,2,3,sep=",") ``` - 可以使用 `sep="你想要的結尾"` - 這邊改成用 `,` 分隔 ---- ## Lab - d483. hello, world [Zerojudge d483](https://zerojudge.tw/ShowProblem?problemid=d483) --- ## stdin ---- ## input() - 會等使用者輸入再繼續跑 - 讀進來都是字串 ---- ## Input example ```python! a = input() print( type(a) ) # str ``` ---- ## Input with prompt ```python! user = input("Enter a name:") food = input("Enter a type of food :") print(user,"is eating",food) ``` ---- ## Lab : on your own 三角形面積計算機 - 讓使用者輸入兩個變數 `width` `height` - 輸出三角形的面積 Example Input: ``` 5 4 ``` Example Output: ``` 10 ``` ---- ## Lab : Zerojudge a001 [a001. 哈囉](https://zerojudge.tw/ShowProblem?problemid=a001) --- ### variables & data types & operator --- ## variables ---- ## variables:變數 ---- ## data type:資料型態 ---- ## variables 變數 - 存放資料 - Python 會幫我們判別變數型態 ---- ## variables Naming 變數命名 - 不能重複命名 - 不能用數字開頭 - 不能用 `+` `-` `*` `/` `%` `&` 連接( 底線 `_` 可以) - 不能使用保留字 - `while` `if` `else` ... ---- ## Correct Naming Example ```python! a=1 b =3.210 c123 = False __12_Jo_= "string obj" signleQuoteStr = '123' ``` ---- ## Mistake Naming Example ```python! 123ouo = 1 a*b-c = d if = None ``` ---- ## Naming Style - Camel Case - `hasCar` `coolBlueBigCar` - Snake Case - `has_car` `cool_blue_big_car` ---- ## readable variables naming 盡量把變數命名的有意義! ---- ## Bad example ``` a=1 ouo="User" c=False __123=456 # .... -> confusing 🤯 ``` ---- ## Good example ``` count = 1 userName = "User" hasCent = False money = 456 ``` ---- ## variable naming for configuration 在專案中用於 **設定相關** 的變數<br>大多會命名成 **底線搭配全大寫** ```python! CLIENT_LIMIT=50 SERVER_NAME="www.jason.com" WORKER_ENABLE=True ``` ---- # Lab > 練習一下 > 看個例子 --- ## data type ---- ## data type 資料型態 Python 基礎的資料型態: - 文字相關 - `str` - 數字相關 - `int` - `float` - 其他 - `bool` - `byte` - `NoneType` ---- ## check data type 如何確認資料型態? ---- ## check data type 如何確認資料型態 ``` print( type(varName) ) ``` ``` num="123" print( type(varName) ) # str ``` ---- ## type casting 如何把「字串」轉乘「整數」呢? 或是 如何把「整數」轉乘「浮點數」呢? ---- ## type casting Examples ```python= num = 123 num_float = float(num) num_int = int(float('2.79')) ``` --- # operator ---- ## operator 運算子 跟一般數學一樣,Python 也可以 `+` `-` `*` `/` ---- ## operator example ```python! print(10*5) a=9 b=7 print(9-7) ``` ---- ## operator example ```python! print(10*5) a=9 b=7 print(9-7) ``` ---- ## divide operator ```python! print(5/3) print(5//3) print( int(5/3) ) ``` ---- ## 除法的陷阱 ```python! print(5/3) # 1.6666666666666667 print(5//3) # 1 print( int(5/3) ) # 1 ``` ---- ## 次方 現在 `a` , `n` 兩個變數,要計算 `a` 的 `n` 次方 ```python! # try it your self ``` ---- ## operator of power 不是 `^` 是 `**` 兩個乘號 ```python! print(3**5) ``` ---- ## mod operator > 有一個在寫程式很常用到的運算子 > 但國中好像還沒教到 > 不過概念很簡單 ---- ## 取餘數 math : ``` a mod b : a/b 的餘數 ``` programming : ``` a%b ``` Example : ``` 16%5 = ? 99%2 = ? 66%3 = ? ``` ---- ## operator between different type 不同型態之前可以運算嗎? ---- ## Example ```python! print(123*123) print("123"*123) print("") ``` ---- ## X = X + 1 <img src="https://pbs.twimg.com/media/Eq3WEN-U0AMP2Lr.jpg" height="600px"/> <!-- ![meme](https://pbs.twimg.com/media/Eq3WEN-U0AMP2Lr.jpg) --> ---- ## X = X + 1 > 不知道變化 > 就每行先 print 出來看看! ---- ## Lab : on your own 輸入 `a` `b` 兩個變數,並輸出以下結果 Example output: ``` a is : 5 b is : 3 The result of a + b is : 8 The result of a - b is : 2 The result of a * b is : 15 The result of a / b is : 1.6666666666666667 The result of a mod b is : 2 The result of a ^ b is : 125 ``` ---- ## Lab : Zerojudge d827 [d827. 買鉛筆](https://zerojudge.tw/ShowProblem?problemid=d827) --- # Python is an interpreter language --- ## Python 是一個直譯語言 (? ---- Compiled language <br> vs <br> Interpreter language ---- 編譯語言 <br> vs <br> 直譯語言 ---- ## 編譯語言 - 由 Compiler (編譯器) 先把 source code <br> compile 成 binary file (二進位檔) - C , C++ , Rust ---- ## 直譯語言 - 由 Interpreter (直譯器) 一行一行執行 <br>(讀到的當下才轉成 `0`跟`1`) - Python , Javascript , PHP ---- ## 既然 Python 是直譯語言 > 那是不是可以 > 一行一行輸入給直譯器跑 ? ---- ## Lab : on your own 來跟 Python Interpreter 玩一下

    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