求教
Topic source| is the union operator; & is the intersection operator;
- is the difference operator; ^ is the symmetric difference operator.
| is the union operator;
& is the intersection operator;
- is the difference operator;
^ is the symmetric difference operator.
在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值;而是,返回它们实际进行比较的值之一。
复制代码
'a' and 'b' 'b' '' and 'b' '' 'a' and 'b' and 'c' 'c' 复制代码 在布尔上下文中从左到右演算表达式的值,如果布尔上下文中的所有值都为真,那么 and 返回最后一个值。
如果布尔上下文中的某个值为假,则 and 返回第一个假值
- 1
Metaphysic
s1=set([1,2,3]) s2=set([2,3,4]) print(s1 and s2) print(s1&s2)
and 和 & 有啥区别?