python 按位运算符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 按位运算符相关的知识,希望对你有一定的参考价值。

# operator | and or
>>> set([1,2,3]) | set([4])
set([1, 2, 3, 4])
>>> set([1,2,3]) or set([4])
set([1, 2, 3])
>>> set([1,2,3]) or set([])
set([1, 2, 3])
>>> set([1,2,3]) | set([])
set([1, 2, 3])
# & operator
a = 6
b = a & -a
# b = 2
# a & -a will return a's first non-0 bit
# a & a's complement
# e.g. 6: 1010, -6: 0110, a&-a = 2 = 0010

以上是关于python 按位运算符的主要内容,如果未能解决你的问题,请参考以下文章

python 按位运算符

AI基础python:openCV——图像算术运算:按位运算

python3练习100题——051

Python 列表到按位运算

Python运算符

Python "按位或"和"按位异或"的区别