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 技術手冊 第三版
485
15
數值處理
你可用運算子(operators,涵蓋於前面的「數值運算」中)和內建函式
(涵蓋於前面的「內建函式」中)進行某些數值計算。Python 也提供
一些模組來支援額外的數值計算,涵蓋於本章:「math cmath 模組」
中的
math
cmath
、「 operator 模組」中的
operator
、「 random 模組」中
random
、「 fractions 模組」中的
fractions
,以及「decimal 模組」中的
decimal
。後面的「gmpy2 模組」也提到第三方的模組
gmpy2
,它進一步地
擴充了 Python 的數值計算能力。數值處理通常會需要,更具體地說,處理
數字所構成的
陣列
arrays
of numbers),涵蓋於後面的「陣列處理」中,
專注於標準程式庫模組
array
和熱門的第三方擴充功能 NumPy
math cmath 模組
math
模組提供用於浮點數字(floating-point numbers)的數學函式;
cmath
模組提供用於複數(complex numbers)的等效函式。舉例來說,
math.
sqrt(-1)
會提出一個例外,但
cmath.sqrt(-1)
會回傳
1j
就跟其他的任何模組一樣,使用它們最簡潔、最易讀的方式是,舉例來
說,在你程式碼的頂端
import math
,並在之後明確地呼叫
math.sqrt
之類
的函式。然而,如果你的程式碼會呼叫該模組的許多知名的數學函式,那
麼作為通用原則的一個例外,在你程式碼的頂端使用
from math ...
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