Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我遇到了这个奇怪的^运算符,我无法理解它的作用
^
简单使用此运算符的结果如下所示:
print "2^4 : ", 2^2 print "4^2 : ", 4^2 print "5^10: ", 5^10 print "10^5: ", 10^5 #2^4 : 0 #4^2 : 6 #5^10: 15 #10^5: 15
这个运算符是什么意思,它具体做什么?
^是按位异或(异或)运算符。
>>> 0b010 ^ 0b110 4 >>> bin(0b010 ^ 0b110) '0b100'
请参阅二进制按位运算。