X = 10 x& = 5 print(x)O / P = o(为什么) [英] X=10 x&=5 print(x) O/P=o(why)
问题描述
在Python 3中
x = 10
x& = 5
print(x)
O / P = o(为什么)
我尝试了什么:
Sir
我对python 3有疑问?
因为这是正确的答案!
将10转换为二进制:1010
转换5到二进制:0101和他们在一起明智地说:
1010
& 0101
----
0000
AND运算符(或__iand__,即& =调用)是一个BINARY运算符:它匹配每个位对并输出组合值,如果位为1在两个输入中,s在结果中为1,否则为0.
尝试
x = 11
x& = 5
print(x)你得到1,因为1011 AND 0101是0001,试试
x = 15
x& = 5
print(x)并且你得到5因为1111 AND 0101是0101。
请参阅 4。内置类型 - Python 3.4.9文档 [ ^ ]。
In Python 3
x=10
x&=5
print(x)
O/P=o(why)
What I have tried:
Sir
I have a doubt in python 3?解决方案Because that is the right answer!
Convert 10 to binary: 1010 Convert 5 to binary: 0101AND them together bits wise:
1010 &0101 ---- 0000The AND operator (or __iand__ which is what &= calls) is a BINARY operator: it matches each bit pair and output the combination value, if a bit is 1 in both input,s it is 1 in the result, otherwise it's 0.
Try
x=11 x&=5 print(x)And you'll get 1, because 1011 AND 0101 is 0001, try
x=15 x&=5 print(x)and you'll get 5 because 1111 AND 0101 is 0101.
See 4. Built-in Types — Python 3.4.9 documentation[^].
这篇关于X = 10 x& = 5 print(x)O / P = o(为什么)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!