Python學習筆記:Day3-數學函式、字元與字串 === [TOC] ## 轉義序列 | 轉義序列 | 名稱 | ASCII碼 | | -------- | ---- | ------- | | \b | 空白 | 8 | | \t | 跳八格 | 9 | | \n | 跳行 | 10 | | \f | 跳頁 | 12 | | \r | 回到此行的前端 | 13 | | \\\ | 反斜線 | 92 | | \\' | 單引號 | 39 | | \\'' | 雙引號 | 34 | ## 萬國碼 print('\u0078') ## 字元轉ASCII碼 code = ord("A") print(code) ## ASCII碼轉字元 ch = chr(40) print(ch) ## 求id print(id('1')) print(id(1)) ## type print(type(0.01)) print(type(1)) print(type('s')) ## lower&upper a = "Hello" print(a.lower()) print(a.upper()) ## strip 刪除空白 b = "\t Welcome" print(b) print(b.strip()) ## 格式化 format(item, format-specifier) #### 科學記號 print(format(57.467,"10.2e")) #### 浮點數 print(format(57.467,"10.2f")) #### 百分比 print(format(0.57467,"10.2%")) #### 對齊 print(format(57.467,"<10.2f")) #### 整數進位 print(format(57467,"10x")) #### 字串 print(format("Welcome","15s")) output如下 ``` x 65 ( 2918191754032 2918190743792 <class 'float'> <class 'int'> <class 'str'> hello HELLO Welcome Welcome 5.75e+01 57.47 57.47% 57.47 e07b ``` ## 實作 ## 訂正 ## 心得 ###### tags: `Python學習筆記`
×
Sign in
Email
Password
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