首页 > 其他 > 详细

数据运算

时间:2016-09-07 23:04:55      阅读:145      评论:0      收藏:0      [点我收藏+]


数据运算:

+ - * / % ** // 取整数,返回商的整数部分,如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
>>>

位运算:二进制的运算

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

数据运算

原文:http://7540500.blog.51cto.com/7530500/1847477

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!