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 技術手冊 第三版
234
|
7 章 核心內建功能和標準程式庫模組
內建函式
7-2 涵蓋了模組
builtins
(在 v2 中是
__builtins__
)中的 Python 函式
(以及一些在實務上只被當成函式使用的型別),以字母順序列出。內建
的名稱
並非
保留字(reserved words)。你可以在區域或全域範疇(scope
繫結是內建名稱的一個識別字(雖然我們建議你避免這樣做,參閱接下來
的警告)。在區域(local)或全域(global)範疇中繫結的名稱會覆寫在內
建範疇(built-in scope)中繫結的名稱:區域或全域名稱會
隱藏
hide
建名稱。你也可以在內建範疇中重新繫結名稱,如前面「Python 的內建物
件」中所涵蓋的。
別隱藏
built-ins
避免意外地隱藏 built-ins:你的程式碼之後可能會需要它
們。你可能會想為你自己的變數取個自然的名稱,像是
input
list
filter
,但
別那樣做
:那些是內建 Python
型別或函式的名稱。除非你養成
永不
以你自己的名稱隱藏
內建名稱的習慣,不然遲早你都會在你的程式碼中遇到因
為這種隱藏意外發生而導致的神秘臭蟲。
有幾個內建函式在 v3 中的運作方式與在 v2 中稍有不同。要移除一些差
異,就在你 v2 模組的開頭使用
from future_builtins import *
:這會使
內建的
ascii
filter
hex
map
oct
zip
v3 的方式運作。(然而,
要在 v2 中使用內建的
print
函式,就用
from __future_ ...
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