牟懋軒
    • 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
    # Print --- # outline 1. 註解(comment) 2. 變數 3. type 4. 運算 5. I/O (input and output) 6. How to google --- # Before Beginning ---- ### 把手伸出來 ![](https://i.imgur.com/dVRy77X.jpg) ---- ## 試試看 ``` print(0.1 + 0.2) ``` --- - BBC電視劇——《蒙提·派森的飛行馬戲團》(Monty Python's Flying Circus)的愛好者 ---- # Zen of Python ### Python 之禪 ---- ``` import this ``` [wiki的翻譯](https://zh.wikipedia.org/wiki/Python%E4%B9%8B%E7%A6%85) --- # 程式運行 ---- 1. 程式語言 2. 0101011000001 3. 運算 4. 得到執行結果 --- # 介紹完Python後 --- # 註解(comment) ---- ## 井字號(#) ## 頭尾三個引號(''' or """) ``` #print("hello") ``` ``` ''' print("hello") ''' ``` ``` """ print("hello") """ ``` ---- ### 功能 - 補充說明 - 不想刪除程式碼 ---- # Question --- ### 變數(variable)and 賦值(=) ---- ## 什麼是變數 ![](https://i.imgur.com/Cq37naJ.jpg =50%x) ---- ### 可以想像成把值(value)丟到箱子裡 ---- #### 直接看code! ``` a = "hello world!" print(a) ``` ---- # 賦值(assign) ### = ? ### == ? ---- - 功能: 1. 新增一個叫做 "a" 的變數 2. 把「hello world」這個字串指派給 "a" 這個變數 ---- ## 功能 1. 可以存值,方便運算 2. 增加易讀性 ---- # 變數名稱的規則 ---- - 變數名稱的開頭必須是字母或者底線,不能以數字開頭 - 變數名稱只能包含字母、數字與底線 (A-z, 0-9, _ ) - 變數名稱的大小寫不一樣則被視為不同變數 (age, Age 和 AGE 是三個不一樣的變數) - 不能是if,else,while等關鍵字 - 不要用函數名稱當變數名字 ---- ### 哪些變數名稱不合法 - zen-of-python - print - 111 - (1) - -.- - ?! - _n ---- ### print 和 _n 都是可以的,但前者不建議,後者有其他用處 ---- # Question --- # 運算子 ---- ``` print(1+1) ``` ---- ``` a = 5 print(-a) ``` ---- [更多運算子](https://www.w3schools.com/python/python_operators.asp) ---- print("hello" + "world") ---- # Question --- # Data Type ---- # type() ---- ``` print(type(1)) ``` ``` print(type(1.0)) ``` ``` print(type("sprout")) ``` ---- # 什麼是 Data Type ---- - 舉例:int, float, string - 不同資料型別能做的事會不太一樣 - 就算對他們做同樣的事,也可能會有不同的結果 - 變數會以不同的資料型態儲存資料 ---- ### try! ``` a = 1 + 1 b = 1 + 1.0 c = "10" + "0" d = "hello" + "world" e = ["a","b"] + ["c","d"] print(type(print)) print(type(type)) print(type(int)) ``` ---- ### 型別轉換 ``` a = "1" a = int(a) ``` ``` b = 1 b = str(b) ``` ---- ### try ``` int(1.5) int("sprout") ``` ---- - 取一個數的小數可以怎麼做呢? ---- ``` a = 2.5 b = int(a) print(a - b) ``` ---- # Question --- # input ---- - 可以輸入什麼? - 可以用什麼設備輸入 ---- ## 有完整的輸入輸出,就可以達到互動的效果 ---- ``` a = input("可寫可不寫的提示訊息") ``` ``` name = input("輸入你的名字: ") print("hello,", name) ``` ---- Question and Practice ### 完成它 ``` Hi, [name]. You're [age] years old next year. ``` ---- ``` name = input() age = int(input()) age = age + 1 # age += 1 age_str = str(age) print("Hi, " + name + ". You will be " + age_str + " years old next year.") print("Hi, " + name + ". You will be" , age ,"years old next year.") ``` ## print #### beginning! ---- ``` print("hello world") ``` ---- ### 等等,那函式(functions)是什麼? ---- #### 你可以把它當作一段特別的關鍵字 - 功用: - 執行特定工作 - 修改參數、引數,重複使用 - 易懂 ---- # 繼續print!! ---- - 以下哪些是會出現error的呢? ``` print("hello" ) ``` ``` print ("hello") ``` ``` print("hello"); ``` ``` print "hello" ``` ``` print(hello) ``` ---- ## answer:第四個、第五個 ---- ``` print("starburst" "stream") ``` ``` print("starburst", "stream") ``` ![](https://i.imgur.com/6g3uV2m.jpg =30%x) ---- ``` print("starburst", "stream",sep="!!") ``` ---- # end ---- ``` print("star", end="") print("burst", end=" ") print("stream", end="!") ``` ---- # 結合 ``` print("starburst", "stream",sep="!!",end=" RRRRRRR") ``` ---- # Question and Practice - 什麼時候會用到end?什麼時候會用到sep? - 玩玩看 sep 和 end - 分別用逗號和 sep 達到和下面程式碼一樣的效果 ``` print("hello" + "world") ``` --- ## print ### 跳脫字元 ---- ## 試著印出以下這段話 ``` "Gura" is a shark ``` ![](https://i.imgur.com/d8fJzpN.png =50%x) ---- ### 透過反斜線,讓後面的符號、字母有其他意義 ``` print("\"Gura\" is a shark") ## 讓gura前後的引號可以顯現 ``` ``` print("nnn\nnn") ## \n 會換行 ``` ``` print("ttt\ttt") ## \t 會一次空一個tab ``` ``` print("xyz\bc") ## b是backspace,會刪掉前一個字元 ``` ``` print("xyzxyz\rabc") ``` ---- ``` \n 是換行的字元 ``` ``` print(r'\n 是換行的字元') ``` ---- # Question and Practice - 用r會不會有哪裡出問題? - 什麼時候會用到\r? ---- # 同一個引號會出問題! ``` print(r'hello \nworld') ``` ``` print(r'hello 'world') ``` ---- # 計時器 ``` import time for i in range(9): i = 9 - i i = str(i) print("\r" + i,end="秒") time.sleep(1) print("\r" + "0 秒",end="") print("\nHappy New Year!!!!") ``` ---- ``` import time s = "sprout" l = len(s) for i in range(l): print("\r" + s[:l-1-i] + "_", end="") # print(".",end="") time.sleep(1) print("______") ``` ---- ``` print("hello world") print("next line!") # 那怎麼不換行 print("a", "b", "c") print("a" + "b" + "c") print("a") # " 和 '有差嗎 print('b') print("I'm Nuss") # print('I'm Nuss') ``` ---- ``` a = "world" b = "Nuss" c = f"hello {a}, I am {b}" d = f"hello {a}, I am {b.lower()}" print(c) print(d) ``` ---- ``` # format的格式用法 import math print(f'The value of pi is approximately {math.pi:.3f}.') table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678} for name, phone in table.items(): print(f'{name:10} ==> {phone:10d}') print(f'The value of pi is approximately {math.pi:07.3f}.') ``` ---- --- # 結語 ---- 綜合練習 & 作業 [neoj 3000](https://neoj.sprout.tw/problem/3000/) [neoj 3008](https://neoj.sprout.tw/problem/3008/) [neoj 3009](https://neoj.sprout.tw/problem/3009/) --- ## 如果你遇到困難 1. 在課堂上 ---- # 我們超多助教! ---- ## 如果你遇到困難 2. 下課後 - 先google看看 - 如果還是無法解決 ---- # 我們超多助教! ---- - 截圖 - 告訴我們你做了哪些努力與嘗試 - 網路上可能沒有正解,但一定會有值得參考的資料 --- # How to google 1. - (刪去後面的關鍵字) - 車子 -廣告 2. "" -> 強調(完全一樣) 3. site - twitter site:youtube.com 4. related - related:youtube.com ---- [link](https://support.google.com/websearch/answer/2466433?hl=zh-Hant) --- # Thanks

    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