Is there no XOR operator for booleans in golang?

前端 未结 2 988
清歌不尽
清歌不尽 2021-02-01 00:38

Is there no XOR operator for booleans in golang?

I was trying to do something like b1^b2 but it said it wasn\'t defined for booleans.

2条回答
  •  悲哀的现实
    2021-02-01 01:05

    With booleans an xor is simply:

    if boolA != boolB {
    
    }
    

    In this context not equal to performs the same function as xor: the statement can only be true if one of the booleans is true and one is false.

提交回复
热议问题