集合演算
和(union)
積(intersection)
差(difference)
和(union) 記号 | 要素の和
例
union = {1,2,3,4} | {6,7,8,9}
print(union)
結果
{1, 2, 3, 4, 6, 7, 8, 9}
積(intersection) 記号 & 被っている要素
例
intersection = {1,2,3,4,'A'} & {4,7,8,9,'A'}
print(intersection)
結果
{4, 'A'}
差(difference)記号 & 左の集合から右の集合を引く残ったもの
difference = {1,2,3,4,5,} - {2,3,4,5,6}
print(difference)
結果
{1}