林劭寰
    • 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
    ###### tags: python python === #### print - or It only print B if A is false or NULL print - print (0 or 1) ## 1 - print(Flase or "hey") ##'hey' - print('hi'or'hey) ##'hi' - print([ ] or False) ## 'False' - print(False or [ ]) ## [] - and and only evalute the second argument if the first one is true - print(0 and 1) ## 0 - print(1 and 0) ## 0 - print(False and 'Hey') ##False - print('Hi' and 'Hey') ## 'Hey' - print([ ] and False) ##[ ] - print(False and [ ]) ## False - operators - & performs binary AND - | performs binary or - ^ Performs a binary XOR operation - ~ performs a binary NOT operation - << shift left operation - ">> shift right operation - other operator - is - in - Ternay operator - use to define conditional def is_adult(age) if age >18: return True else: return False def is_adult2(age) return True if age>18 else False - print with different line - 三個"可以做成很多行的輸出(若第一行的"後面沒接東西,就會變成多一行空格) - print("""Beau is 39 years old. """) 輸出 Beau is 39 years old. - string modify 上述這些都只是輸出當下改變的string。但本身的string值是不變的。 - isalpha() 去確定string裡面只有charactres 且不是空的 - isalnum() 確定string裡面只有character跟digits 且不是空的 - isdecimal() 確定string 裡面只有數字且不是空的 - print("BEAU".lower()) >beau - print("beau".upper()) >BEAU - print('bEAu person'.title()) it make first leeter of each string become capital letter >Beau Person - print("Beau person".islower()) > False - print("person".islower()) > True is lower 是用來確定整個string是否都是小寫 - startsswith() to check if the string starts with a specific substring - endswith() to check if the string ends with a specific substring - replace() to replace a part of a string - split() to split a string on a specific charactr separator - strip() to trim the whitespace from a string - join () to append new letters to a string - find () to find the postion of a substring - global function - print(len(name)) > 4 - name ="beau" print("au" in name) > True - name ="Be\"au" print(name) > BE"au \這個可以讓後面的"不再表示成本來的樣子,而是一般的string - name = 'Be"au' print(name) > Be"au - name ='Be"\'au' print(name) > Be"'au - name = 'Be\nau' print(name) > Be > au - name ='Be\au' print(name) > Beu - name = 'Be\\au' print(name) > Be\au - name ="Beau" print(name[1:2]) 從1開始回值,2之前的全部丟出來(不包含2) - any([A,B]) it will return true if any value of this function is true - all([A,B]) it will return true if all of the value is true - complex - turn complex = 2+3j; num = complex(2,3) print(num2.real, num2.imag) > 2.0 3.0 - abs(絕對值) and round - print(abs(-5.5)) > 5.5 - round - print(round(5.49, 1)) > 5.5 會收斂在小數點下面第一位 - print(round(5.4)) > 5 - print(round(5.5)) > 6 ### Enum > from enum import Enum > class State(Enum): > INACTIVE = 0 > ACTIVE = 1 > print(State.ACTIVE.value) output: 1 > print(State(1)) output: State.ACTIVE > print(State['ACTIVE'].value) output: 1 > print(list(State)) output <State.INACTIVE: 0>,<State.Active: 1> > print(let(State)) 2 ## Basic input output > age = input("what is your age?\n") > print("your age is "+age) output: what is your age? >55 >your age is 55 ## List dogs = ["Roger",1,"Syd",True] print("If Roger is in the list just print True\n") print("Roger" in dogs) >print(dog[:3]) ['Roger',1,'Sys'] >print(len(dogs)) 4 - append & edit - edit > dogs[2]=beau > print(dog[2]) beau - append dogs.append('Judah') 會把Judah加到最後面的分項去 - extend dogs.extend(['Judah',5]) 把兩格分項都加到後面去,可以加一整個list - dogs+=['Judah',5]跟上面的結果是相同的 #### 若把Append加上list,整個list會變成最後分項,而不是多個獨立的。 #### 但若是寫成Dogs +="Judah"整個會被拆成'J','u','d','a','h',所以一定要記得加上[] - remove(移除) dogs.remove('Syd') - 這樣syd會從裡面被移除,但要小心確認他有在list裡面,沒有整個program就會error。 - pop remove the last item in the list , and print it. And this thing will not on the list anymore. - insert items.insert(2,"test") 這樣item的第三項(從零開始算的)就會插入test,本來的index 2位置的,就會往後排。 #### 但你若是要插入多個的話,可以試試看這個 items[1:1]=["test1","test2"] 這樣就會從index 1開始插入test1跟test2,其他的項目往後遞延 #### sort - items.sort() 會把items這個list由大寫的第一個字順序到小寫的第一個字順序來排序。 - items.sort(key=str.lower) 會不分大小寫,照alphabet的順序來先做排列。 - itemscopy=items[:] 可以先行複製item內容,讓值被變更的同時可以保留他的原本樣貌 - print(sorted(items,key=str.lower)) 可以不變動本來item的樣子,只有輸出時來做排列改變 --- ## Tuples Tuple用()表示,Tuple一旦建立就不可再變更,要新增元素的話只能創新的Tuple後面再加。 you can't modify the original tuple > names = ("Roger", "Syd") > newTuple=names+("Tina","Quincy") ## Dictionaries - dog={"name":"Roger", "age":8, "color":"green"} print(dog.get("color","brown")) >輸出狗的顏色,若是沒有就輸出brown - print(dog.pop("name")) print(dog) >此時name就會消失,因為被pop掉了 - print(dog.popitem()) >最後被加入的會被拿掉,是Color會消失 - print(dog.keys()) >輸出所有的值 >dict_keys(['name','age,'color']) - print(list(dog.values())) >['Roger',8,'green'] 因為使用了List所以變成[] - dog["favorite food"]="meat" 這樣最後就可以輸出多一項favorite food, meat - del dog['color'] 這樣就可以把顏色刪除 - copy() dogCopy = dog.copy() 這樣就可以copy dictionary ## sets

    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