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 技術手冊 第三版
資料型別
|
55
Python
唯一不能成為三引號字串內容一部分的字元是未轉義(unescaped)的反
斜線,然而一個帶引號字串(quoted string)不能包含未轉義的反斜線、
斷行,或是圍住它的引號字元。反斜線字元起始一個
轉義序列
escape
sequence
,這能讓你在上述任一種字串中引入任何字元。我們在表 3-1
列出了 Python 的字串轉義序列。
3-1 字串轉義序列
序列 意義 ASCII/ISO 代碼
\<newline>
忽略行結尾
\\
Backslash(反斜線)
0x5c
\'
Single quote(單引號)
0x27
\"
Double quote(雙引號)
0x22
\a
Bell
0x07
\b
Backspace(退格)
0x08
\f
Form feed
0x0c
\n
Newline(新行)
0x0a
\r
Carriage return
0x0d
\t
Ta b
0x09
\v
Vertical tab
0x0b
\ DDD
八進位值
DDD
如給定的
\x XX
十六進位值
XX
如給定的
\ other
任何其他(other)字元:一個雙字元的字串
0x5c
+ 如給定的
字串字面值的一個變體是
原始字串
raw string
。語法跟帶引號或三引號
字串字面值相同,只不過前導引號的前面緊接著一個
r
R
。在原始字串
中,轉義序列不會像表 3-1 所記載的那樣被解讀,而是照字面被複製到字
串中,包括反斜線和 newline 字元。原始字串語法適用於包含許多反斜線
的字串,特別是正規表達式的模式(regular expression ...
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