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 技術手冊 第三版
72
|
3 章 Python 語言
指數
指數(「次方」)運算,
a**b
,當
a
小於零而
b
是一個帶有非零小數部分的
浮點數,在 v2 中就會提出一個例外,但在 v3 中,它會回傳適當的複數。
內建的
pow(a, b)
函式回傳與
a**b
相同的結果。帶有三個引數的話,
pow(a, b, c)
就會回傳與
(a**b)%c
相同的結果,但會比較快。
比較
所有的物件,包括數字,都可以比較相等性(
==
)和不等性(
!=
)。順序的
比較(
<
<=
>
>=
)可以用於任何兩個數字之間,除非有任一個運算元
是複數,在那種情況下它們會提出執行時期例外。所有的這些運算子都會
回傳 Boolean 值(
True
False
)。要當心浮點數的相等性比較,如線上教
學指南(
https://docs.python.org/3.5/tutorial/floatingpoint.html
)中解釋的。
整數上的位元運算
整數可以被解讀為位元字串(strings of bits),並可用於表 3-2 中所展示
的位元運算(bitwise operations)。位元運算子的優先序比算術運算子
還要低。正整數(positive integers)在概念上會由左邊長度不定的
0
元字串所延展。負整數(negative integers),因為是由二補數法(two
s
complement
https://en.wikipedia.org/wiki/Two's_complement
)來表示,所以
在概念上是由左邊長度不定的
1
位元字串所延展。
序列運算
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