Python Set union() Yöntem
Örnek
Her iki kümedeki tüm öğeleri içeren bir küme döndür, yinelenenler hariç tutulur:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.union(y)
print(z)
Tanım ve Kullanım
Yöntem union()
, orijinal kümedeki tüm öğeleri ve belirtilen kümelerdeki tüm öğeleri içeren bir küme döndürür.
Virgülle ayırarak istediğiniz kadar set belirleyebilirsiniz.
Bir küme olması gerekmez, yinelenebilir herhangi bir nesne olabilir.
Bir öğe birden fazla sette mevcutsa, sonuç bu öğenin yalnızca bir görünümünü içerecektir.
Sözdizimi
set.union(set1, set2...)
Parametre Değerleri
Parameter | Description |
---|---|
set1 | Required. The iterable to unify with |
set2 | Optional. The other iterable to unify with. You can compare as many iterables as you like. Separate each iterable with a comma |
Daha fazla örnek
Örnek
2'den fazla seti birleştirin:
x = {"a", "b", "c"}
y = {"f", "d", "a"}
z = {"c", "d", "e"}
result = x.union(y, z)
print(result)