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 技術手冊 第三版
120
|
4 章 物件導向的 Python
本章也在後面的「特殊方法」一節中涵蓋
特殊方法
special methods
在後面的「抽象基礎類別」中涵蓋叫做
抽象基礎類別
abstract
base classes
的進階概念;在後面「裝飾器」一節中涵蓋
裝飾器
decorators
,並在後面的「元類別」中涵蓋
元類別
metaclasses
類別與實體
如果你熟悉其他語言(例如 C++ Java)的物件導向程式設計,你對類
別(classes)與實體(instances)大概就有很好的直觀理解:一個
類別
class
是使用者所定義的型別(user-defined type),你能夠將之
實體化
instantiate
以建立
實體
instances
,也就是該型別的物件。Python
過它的類別和實體物件來支援這些概念。
Python 類別
一個
類別
class
是帶有下列幾個特徵的一個 Python 物件:
你可以把一個類別物件(class object)當成函式來呼叫。這個一般稱為
實體化
instantiation
的呼叫,會回傳一個物件,它叫做該類別的一
實體
instance
,而那個類別則被稱為該實體的
型別
type
一個類別有你能夠繫結(bind)和參考(reference)的任意命名的屬性
attributes)。
類別屬性的值可以是
描述器
descriptors
,包括函式),涵蓋於後面的
「描述器」中,也可以是一般的資料物件。
繫結至函式的類別屬性叫做該類別的 ...
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