python运算符

Python数据运算

http://www.runoob.com/python/python-operators.html

http://www.cnblogs.com/alex3714/articles/5465198.html

算数运算:

 

比较运算:

 

赋值运算:

 

>>> a = 21
>>> b = 10
>>> c = 0
>>> print(c)
0
>>> c = a + b
>>> print(c)
31
>>> print(c)
31
>>> c += a
>>> print(c)
52
>>> c *= a
>>> print(c)
1092
>>> c /= a 
>>> print(c)
52.0
>>> c = 2
>>> print(c)
2
>>> c %= a
>>> print(c)
2
>>> c **= a
>>> print(c)
2097152
>>> c //= a
>>> print(c)
99864
>>> >>> 

 

 

逻辑运算:

 

成员运算:

 

身份运算:

 

位运算:

 

按位运算符是把数字看作二进制来进行计算的。Python中的按位运算法则如下:
下表中变量 a 为 60,b 为 13,二进制格式如下:
a = 0011 1100

b = 0000 1101
-----------------

a&b = 0000 1100

a|b = 0011 1101

a^b = 0011 0001
~a  = 1100 0011

 

运算符优先级:

 

posted on 2017-03-24 10:30  光阴8023  阅读(115)  评论(0编辑  收藏  举报