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

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

算数运算:

Python数据运算

比较运算:

 Python数据运算

赋值运算:

 Python数据运算

>>> 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数据运算

成员运算:

 Python数据运算

身份运算:

 Python数据运算

位运算:

 Python数据运算

按位运算符是把数字看作二进制来进行计算的。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

 

运算符优先级:

Python数据运算

 

相关文章:

  • 2021-06-10
  • 2021-09-20
  • 2022-01-12
  • 2021-10-07
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-09-25
猜你喜欢
  • 2021-12-17
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-27
  • 2022-02-09
相关资源
相似解决方案