# Python CodeRecipe|intersection()の使い方
❮ Home ❮ Set Methods
# intersection()の例1
Return a set that contains the items that exist in both set
x, and set y:
x =
{"apple", "banana", "cherry"}y = {"google",
"microsoft", "apple"}z = x.intersection(y)
print(z)
# intersection()の定義及び使い方
intersection()関数は、 2つ以上のセット間の類似性を含みます。 意味:戻されるセットには、両方のセットに存在するアイテムのみが含まれます。 比較が3つ以上のセットで行われた場合は、すべてのセット。
# intersection()の構文
set.intersection(set1, set2 ... etc)
# intersection()の引数
パラメータ 説明
set1 必須. The set to search for equal items in
set2 オプション. The other set to search for equal items in.You can compare as many sets you like.Separate the sets with a comma
# Example
Compare 3 sets, and return a set with items that is present in all 3 sets:
x =
{"a", "b", "c"}y = {"c",
"d", "e"}z = {"f",
"g", "c"}result = x.intersection(y, z)print(result)
❮ Home ❮ Set Methods