Pipe character in Python

I see a "pipe" character ( | ) used in a function call:

res = c1.create(go, come, swim, "", startTime, endTime, "OK", ax|bx)

What is the meaning of the pipe in ax|bx ?


It is a bitwise OR of integers. For example, if one or both of ax or bx are 1 , this evaluates to 1 , otherwise to 0 . It also works on other integers, for example 15 | 128 = 143 15 | 128 = 143 , ie 00001111 | 10000000 = 10001111 00001111 | 10000000 = 10001111 in binary.


这也是联合集合运算符

set([1,2]) | set([2,3])

按位或。

链接地址: http://www.djcxy.com/p/38646.html

上一篇: 如何在Django ModelForm中过滤ForeignKey选项?

下一篇: Python中的管道字符