What does ^=
do in python?
I'm uncertain of whether ^
and ^=
are similar or related in their name or behavior.
Example question:
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
nums = [3,3,4,2,2]
def singleNumber(self, nums: List[int]) -> int:
a = 0
for i in nums:
a ^= i
return a
I expect the output to be 4
in this case. But I have yet to find any definitive resource explaining how the ^=
operator works.
Please explain what it is & how it works.