小编M. *_*ley的帖子

为什么Python"&="设置运算符的行为与"&="整数运算不同?

为什么设置操作更改设置s?对于同一运算符的整数(按位)版本,它的工作方式不同....

设置操作&=(更改s):

s = set('abc')
t = set('bcd')
u=s
print u, s, t
u &= t
print u, s, t
Run Code Online (Sandbox Code Playgroud)

结果:

set(['a', 'c', 'b']) set(['a', 'c', 'b']) set(['c', 'b', 'd'])

set(['c', 'b']) set(['c', 'b']) set(['c', 'b', 'd'])
Run Code Online (Sandbox Code Playgroud)

按位运算&=(不变s):

s = 7
t = 3
u=s
print u, s, t
u &= t
print u, s, t
Run Code Online (Sandbox Code Playgroud)

结果:

7 7 3

3 7 3
Run Code Online (Sandbox Code Playgroud)

python python-2.7

5
推荐指数
1
解决办法
70
查看次数

标签 统计

python ×1

python-2.7 ×1