im curious about how the logical operators work in sets. cosider this:
x = set('abcde')
y = set('bdxyz')
# union
print(x | y) # output: {'d', 'b', 'y', 'e', 'z', 'x', 'c', 'a'}
print(x or y) # output: {'d', 'b', 'e', 'c', 'a'}
# intersection
print(x and y) # output: {'d', 'b', 'y', 'z', 'x'}
print(x & y) # output: {'b', 'd'}
i expected the outputs for union and intersection to be the same for each. how is it possible that they are not? can anyone explain?
sets. This is howandandorwork for all types. Try1 or 2and50 or 0.x or yis not the same asx | y. The latter is the the union for sets. The former is saying return the first Truthy value.