+ 1
Operator '^'
What does the list operator '^' do?
2 Respostas
+ 9
^ is the bitwise XOR (exclusive or - one or the other but not both) operator. See
https://jakevdp.github.io/WhirlwindTourOfPython/04-semantics-operators.html#Bitwise-Operations
The ^ operator will perform a binary XOR in which a binary 1 is copied if and only if it is the value of exactly one operand. Another way of stating this is that the result is 1 only if the operands are different.
Examples include:
# 0 ^ 0 = 0
# 0 ^ 1 = 1
# 1 ^ 0 = 1
# 1 ^ 1 = 0
# 60 = 0b111100
# 30 = 0b011110
60 ^ 30
# Out: 34
# 34 = 0b100010