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 技術手冊 第三版
267
8
字串類的東西
v3 以型別
str
支援 Unicode 文字字串(text strings),具有運算子、內建函
式、方法,以及專用的模組。它也提供在某些方面類似的
bytes
型別,以
位元組序列(sequence of bytes)表示任意的二進位資料(binary data),
也被稱為
bytestring
位元組字串
byte string
。這是與 v2 的主要差
異,在 v2 中,
str
是位元組所成的序列,而 Unicode 文字字串的型別則是
unicode
。許多文字運算,在兩個版本中,都能在其中任一個型別的物件上
進行。
本章在「字串與位元組物件的方法」一節中涵蓋字串物件的方法,在「字
串格式化」中涵蓋字串的格式化,並涵蓋模組
string
(「 string 模組」中)
pprint
(「 pprint 模組」中)。與 Unicode 有關的特定議題也有涵蓋,在
後面的「Unicode」中。新的(v3.6)格式化字串字面值(formatted string
literals)涵蓋於「3.6 中的新功能:格式化字串字面值」。
字串與位元組物件的方法
Unicode
str
bytes
物件是不可變的序列(immutable sequences),如前
面「字串」一節中所涵蓋的。不可變序列的所有運算(重複、串接、索引
與切片)都能套用到它們身上,並會回傳相同型別的一個物件。字串或位
元組物件
s
也提供了數個非變動式的方法,如表 8-1 中所記載。
268
|
8 章 字串類的東西
除非特別提到,不然上述任一個型別的物件上都有這些方法可用 ...
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