Please explain ^ operator on Python. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please explain ^ operator on Python.

16th Jul 2017, 2:52 PM
Devashish gupta
Devashish gupta - avatar
2 Answers
+ 8
^ is xor gate operator 5^3 = 9 05 = 00000101b 12 = 00001100b ^ 09 = 00001001b
16th Jul 2017, 3:03 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 8
It also works for collections, like sets and means eXclusive OR - returns only those items which are in a set A but not B or B but not A. A = {1, 2, 3, 4} B = {3, 4, 5, 6} A^B = {1, 2, 5, 6} # 3 and 4 are in both sets
16th Jul 2017, 7:50 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar