Pythonトレーニング


3.7 イテラブルのその他の機能

3.7.1 集合の機能

a = {"dog", "cat", "mouse"}
b = {"lion", "cat"}

print(a | b)
->{'cat', 'mouse', 'lion', 'dog'}

print(a & b)
->{'cat'}

print(a - b)
->{'dog', 'mouse'}

print(a ^ b)
->{'mouse', 'dog', 'lion'}
a = {"dog", "cat", "mouse"}
b = {"dog", "cat"}
c = {"dog", "cat"}

print(a == b)
->False

print(a != b)
->True

print(a > b)
->True

print(a >= b)
->True

print(b == c)
->True

print(b != c)
->False

print(b > c)
->False

print(b >= c)
->True