【Python】集合の対称差演算子

はじめに

集合A ^ 集合Bで、集合Aと集合Bの差の集合ができる。

ソースコード

symmetric_difference.py · ki-hi-ro/python@2f5ca39

set_a = {1, 2, 3, 4, 5}
set_b = {2, 3}
symmetric_diff = set_a ^ set_b
print("Symmetric difference between set_a and set_b:", symmetric_diff)

symmetric_diffに集合の対称差が入る。

実行結果

Symmetric difference between set_a and set_b: {1, 4, 5}

set_aとset_bの対称差は、{1, 4, 5}

set_a = {1, 2, 3, 4, 5}
set_b = {2, 3}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です