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 技術手冊 第三版
490
|
15 章 數值處理
operator 模組
operator
模組提供與 Python 運算子(operators)等效的函式。這些函式
在那些 callables 必須被儲存、作為引數傳遞,或作為函式結果回傳時很
方便。
operator
中的函式之名稱與對應的特殊方法(涵蓋於前面的「特殊
方法」中)相同。每個函式都有兩個名稱可用,帶有和不帶有「dunder
(前導及尾隨的兩個底線)的名稱:舉例來說,
operator.add(a,b)
operator.__add__(a,b)
都會回傳
a+b
。矩陣乘法(matrix multiplication
的支援在 v3
1
中被新增為中置運算子(infix operator),但(在本文寫作之
時)你必須定義你自己的
__matmul__()
https://docs.python.org/3/reference/
datamodel.html#object.__matmul__
)、
__rmatmul__()
https://docs.python.
org/3/reference/datamodel.html#object.__rmatmul__
)和(選擇性的)
__
imatmul__()
https://docs.python.org/3/reference/datamodel.html#object.__
imatmul__
)以定義它,不過 NumPy 就有支援
@
(但尚未支援
@=
)以進行
矩陣乘法。
15-2 列出了
operator
模組所提供的某些函式。 ...
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