Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
字串格式化
|
279
8-4 
格式型別 格式化說明
'b'
二進位(binary)格式,一系列的零與一
'c'
其序數值(ordinal value)是被格式化的值的 Unicode 字元
'd'
十進位(decimal,預設的格式型別)
'o'
八進位(octal)格式,一系列的八進位數字
'x'
'X'
十六進位(hexadecimal)格式,一系列的十六進位數字,帶有小寫或
大寫的字母
'n'
十進位格式,有設定系統的地區設定(system locale)的話,就帶有地
區特定(locale-specific)的分隔符(UK US 的逗號)
浮點數(floating-point numbers)具有不同的一組格式型別,如表 8-5
所示。
8-5 
格式型別 格式化說明
'e'
'E'
指數(exponential)格式,科學記號(scientific notation),帶有介於
一與九之間的整數部分,在指數前使用
'e'
'E'
'f'
'F'
定點(fixed-point)格式,可能會有大寫或小寫的無限(
'inf'
)或非數
字(
'nan'
'g'
'G'
通用(general)格式,可能的話就用定點格式,否則就用指數格式;依
據格式型別的大小寫使用小寫或大寫的
'e'
'inf'
'nan'
'n'
就像通用格式,但在有設定系統地區設定時,使用地區特定的分隔符來
為數字分組或用於小數點
'%'
百分比(percentage)格式,將值乘以 100 並將之格式化為後面接著
'%'
的定點格式
若沒指定格式型別,一個
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819