一械馆、真值的定義Truth Value
除以下情形外的定義均為真值:
1.定義常量為 None
或者 False
.
2.數(shù)值定義中的0,如:0
, float(0.0)
,
3.空序列侣集、空字典、空集合厅缺、空對(duì)象等如: ()
, []
, {}
, set()
, range(0)
二、and
, or
, not
|
|
|
x and y |
x為真且y為真則為真,否則為假 |
與 |
x or y |
x為假且y為假則為假,否則為真 |
或 |
not x |
x為真則為假疗韵,否則為真 |
非 |
三、比較Comparisons
|
|
< |
1 < 2 |
<= |
2 <= 2 |
> |
3 > 2 |
>= |
3 >= 2 |
== |
2 == 2 |
!= |
3 != 2 |
is |
'123' is '123' |
is not |
'123' is not '123' |
四侄非、加減乘除
東西太簡(jiǎn)單了蕉汪,直接摘抄官網(wǎng)的
|
|
x + y |
sum of x and y
|
x - y |
difference of x and y
|
x * y |
product of x and y
|
x / y |
quotient of x and y
|
x // y |
floored quotient of x and y
|
x % y |
remainder of x / y
|
-x |
x negated |
+x |
x unchanged |
abs(x) |
absolute value or magnitude of x
|
int(x) |
x converted to integer |
float(x) |
x converted to floating point |
complex(re, im) |
a complex number with real part re, imaginary part im.im defaults to zero. |
c.conjugate() |
conjugate of the complex number c
|
divmod(x, y) |
the pair (x // y, x % y)
|
pow(x, y) |
x to the power y
|
x ** y |
x to the power y
|
五、按位運(yùn)算
|
|
x | y |
bitwise or of x and y |
x ^ y |
bitwise exclusive or of x and y |
x & y |
bitwise and of x and y |
x << n |
x shifted left by n bits |
x >> n |
x shifted right by n bits |
~x |
the bits of x inverted |
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者