首页 > 代码库 > 数据运算

数据运算


数据运算:

+ - * / % ** // 取整数,返回商的整数部分,如9/2输出结果4,9.0/2.0输出结果4.0

>>> 9//2
4
>>> 9.0//2.0
4.0
>>> 9.0//2.5
3.0
>>> 9.0//2.4
3.0
>>> 9.0//2.3
3.0
>>> 9.0//2.2
4.0
>>> 9.0//2.1
4.0
>>>

==
!=  <>
>
<
>=
<=


赋值:
=
+=
-+
*=
/=
%=
**=
//=

逻辑运算:

and
or
not

>>> a,b,c = 3,5,7
>>> print(a,b,c)
3 5 7
>>> a > 2 and c < 7
False
>>> a > 2 and c < 8 and b > 4
True
>>> if not a > 2 and c < 8 and b > 4:
...   print(‘bbb‘)
...
>>> if not a < 2 and c < 8 and b > 4:print(‘bbb‘)
...
bbb
>>>



成员运算:
in
not in

身份运算:
is            #判断两个标识符是不是引用自同一个对象
is not
>>> a = [1,2,3]
>>> type(a) is list
True
>>> type(a) is not list
False
>>> "abc" is "abc"
True
>>> "abc" is "abcd"
False
>>>

位运算:二进制的运算

&  按位与
|  按位或
^  按位异或
~  按位取反
<< 左移动
>> 右移动

数据运算