+ 8
The operator | has different functions depending on the types to its left and to its right. set|set returns the unsion of two sets but int|int returns the binary "or" of two numbers now 1 = 1 in binary 2 = 10 in binary and therefore 1|2 evaluates to 11 in binary = 3 in decimal system and therefore {1|2} evaluates to {3} now in {3}|{1}|{2} we have the | as union of sets and it evaluates to {1,2,3}
19th Feb 2022, 11:31 AM
Oma Falk
Oma Falk - avatar