YuKai0928
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- ###### tags: `資訊之芽` --- # 1st Stage Review 資芽北區2023 講師: 洪郁凱Kain --- ## Outline - Review Syntax - What's next? --- ## Review Syntax 練習用python內建的manual整理自己的重點 `help(...)` ![](https://i.imgur.com/P2242DO.png =40%x) ---- ## Review Syntax ``` basic if--else list string while for dictionary function import ``` ---- ## Review Syntax basic 加減乘除 ```python # Between int/float/complex # + - * ** / // % # __add__, __sub__,... print(1 + 1, 2 - 1.0, 3 * 3, 4+5j / 3) print(1.2e3 // 3, 5**4, 3%2) # +=, -=, *=, /= a = 5 print(a) a += 3 print(a) ``` ![](https://i.imgur.com/EAu2DWX.png) ---- ## Review Syntax basic 輸入 ```python str_a = input() # 字串 a, b = str_a[:2], str_a[2:] #切下前兩個字分給a,剩下分給b num = int(input()) # 單個數字 num = eval(input()) # 單個數字(可輸入:7.0,1+5j...) strs_a = input().split(" ") # 用" "分隔的多個字 以list裝 n, m = map(int, input().split()) # 兩個數字 nums = list(map(int, input().split())) # 多個數字 以list裝 ``` ---- ## Review Syntax basic 輸出 ```python print(1, 2, 3,sep=', ',end=".") # "1, 2, 3." num = 12 print(f"{num}\t{num*10}\t{num*100}") # 用Tab對齊 print(" "*(5-len(str(num)))+str(num)) # " 12" 向右靠齊 長度為5 print(str(num).rjust(5)) # " 12" 向右靠齊 長度為5 print(f"{num:05}") # "00012" 補0 長度為5 print(str(num).center(5)) # " 12 " 置中 長度為5 ``` <!-- .element: class="wrap-code" --> ---- ## Review Syntax basic 輸出 ```python a=17 print(bin(a), oct(a), hex(a)) # 0b10001 0o21 0x11 print(bin(a)[2:], oct(a)[2:], hex(a)[2:]) # 10001 21 11 ``` --- ## Review Syntax if-elif-else ```python= a = int(input()) if a%3 == 0: print("三的倍數") elif a%3 == 1: print("減一後是三的倍數") else: # 不用條件 print("減二後是三的倍數") ``` ---- ## Review Syntax Boolean ```python # Between int/float print(1.5>0,1<0,1==0) # Between strings lists /sets print("aa">"ab","ba">"abbbbb") # logic: and, or, not, (xor) print(3>2 and 3<2, 3>2 or 3<2, not 3<2) ``` --- ## Review Syntax while (Collatz conjecture) ```python a = 17 while a>1: print(a) if a % 2: a = 3*a + 1 else: a = a // 2 if a == 928: print("講師的生日!") break # 跳出loop # continue ``` --- ## Review Syntax for (讓程式跳舞) ```python for i in range(1,10): if i == 5: continue print(i) ``` --- ## Review Syntax list ```python list_a = [1,4.2,3+4j,"5",lambda x:x%3] # 可以裝幾乎所有東東 print(list("Baby Shark")) # ['B', 'a', 'b', 'y',... print(["Baby Shark"]) # ['Baby Shark'] print(list_a[2:4]) # slice 取index = 2~3的部分 print(list_a[0]) # 取值 從0開始 print(list_a[4](list_a[1])) # 取值 結合 lambda function list_b = [1,5,2,4,3] print(sorted(list_b)) # 會回傳排好的list 但不會更改本來的list list_b.sort(key=list_a[-1]) # key指定排序規則 list可用-1來取值 sort會將本來的list改變 print會噴None print(list_b) ``` ---- ## Review Syntax list 增刪修 ```python # 增 list_a = [i*10 for i in range(3)] # [0, 10, 20] list_a.append(30) # [0, 10, 20, 30] list_a.extend([i*10 for i in range(3,6)]) # [0, 10, 20, 30, 30, 40, 50] # 刪除 list_a.pop(1) # [0, 20, 30, 30, 40, 50] list_a.remove(30) # [0, 20, 30, 40, 50] del list_a[3:] # [0, 20, 30] # 修 list_a[0] = sum(list_a) # [50, 20, 30] ``` ---- ## Review Syntax list(多維度) ```python list_c = [[i*3 for i in range(1,j)] for j in range(10,2,-2)] print(list_c[2][1]) print(sorted(list_c, key=lambda x:x[-1]%5, reverse=True)) # 根據元素[-1]來排列元素 由大到小 list_d = list(range(1,10,3)) # 另一個生大list的方法 sorted(list_c, key=lambda x:len(x))# 根據元素的長度(元素數量)排序 由小到大 ``` <!-- .element: class="wrap-code" --> ---- ## Review Syntax list + for ```python list_d = [[[i*3 for i in range(1,j)] for j in range(10,k,-2)] for k in range(2,5)] for i in list_d: for j in i: print(j) for k in j: print(k) ``` --- ## Review Syntax string ```python print("Kain"+","+"the student") print("Kain"*3) print(("Kain"*2)[2:5]) # 取值的運算子比乘法優先 print(','.join(["a","b","c"])) # 用join把字串黏起來 print(" Kain ".strip()) # 去掉前後空白 ``` ---- ## Review Syntax string 之前的[練習](https://hackmd.io/@s3131212/rkZYT74lh#/11/2) ```python lyrics = """Never gonna give you up Never gonna let you down Never gonna run around and desert you """ positions = [] start = 0 value = "gonna" while True: ret = lyrics.find(value, start) if ret == -1: break positions.append(ret) start = ret + len(value) print(positions) ``` ---- ## Review Syntax string 太多了真的列不完... ```python help(str) ``` --- ## Review Syntax dictionary ```python d = {1:2, 3.0:4, '5':6+7j} # {key: value...} print(len(d)) # Key-Value pairs/元素數量 亦可用在list/str print(d[1], d['3']) # 取值 print(d.get("Dior","不存在!")) # 避免取到不存在的Key # 檢查 key / combo skill if 3 in d: print(d[3]) # 增/刪/修 d[8] = "nine" del d[1] d.pop(8) d['5'] = 1011 ``` ---- ## Review Syntax dictionary 遍歷 ```python for k, v in d.items(): print("key = {}, value = {}".format(k,v)) # format string ``` --- ## Review Syntax function ```python def func_a(a,b,c,/,d,*,e = 3): # 預設值從後向前 print(a,b,c,d,e) return a,c,e,b,e # return自動包成tuple func_a(10,20,30,40,e=50) func_a(10,20,30,e=40,d=50) func_a(*[10*i for i in range(4)]) # 用list餵參數 func_a(*[10*i for i in range(3)],**{"d":123,"e":456}) # list-> args, dict-> kwargs ``` --- ## Review Syntax import ```python import math import numpy as np from random import randint print(math.sin(math.pi/6)) print(np.array([1,2,3])) print(randint(5,10)) ``` --- ## What's next? Debug 的萬用工具 ![](https://i.imgur.com/jGLwM2k.png =50%x) ---- ## What's next? 基本語法完成之後,可在第二階段學習不同套件,達成更多運用 ---

    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