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 技術手冊 第三版
string 模組
|
273
no_vowels = dict.fromkeys(ord(x) for x in 'aeiou')
print(u'some string'.translate(no_vowels))
# 出: sm strng
這裡有將所有母音變為 a 並刪除 s v2 範例:
intoas = string.maketrans('eiou','aaaa')
print('some string'.translate(intoas))
# 出: sama strang
print('some string'.translate(intoas,'s'))
# 出: ama trang
Unicode v3 的等效程式碼會是:
intoas = dict.fromkeys((ord(x) for x in 'eiou'), 'a')
print(u'some string'.translate(intoas))
# 出: sama strang
intoas_nos = dict(intoas, s='None')
print(u'some string'.translate(intoas_nos))
# 出: ama trang
upper s.upper()
回傳
s
的一個拷貝,其中所有的字母,如果有的話,全都轉為大寫
uppercase)。
a
請注意,這並不包含用作基數(radix)的標點符號,例如點號(
.
)和逗號(
,
)。
string 模組
string ...
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