Metoda .update()
Metoda modyfikuje zawartość set’a, na którym zastosowano metodę. Zmodyfikowany zbiór zawiera sumę zbioru, na którym została zastosowana metoda ze zbiorami z argumentów.
Składnia:
set.update(set2, set3, ...)
set.update(set2, set3, ...)
set.update(set2, set3, ...)
Parametry:
set2 – zbiór porównywany ze zbiorem, na którym została zastosowana metoda
set3, … – parametry opcjonalne – kolejne zbiory
Wartość zwracana:
None
Przykłady:
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set1.update(set2)
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set1 |= set2
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set3 = {10, 11}
set1.update(set2, set3)
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set3 = {10, 11}
set1 |= set2 | set3
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set1.update(set2)
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set1 |= set2
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set3 = {10, 11}
set1.update(set2, set3)
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
set1 = {1, 2, 3, 4, 5, 6}
set2 = {4, 5, 6, 7, 8, 9}
set3 = {10, 11}
set1 |= set2 | set3
print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
set1 = {1, 2, 3, 4, 5, 6} set2 = {4, 5, 6, 7, 8, 9} set1.update(set2) print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9} set1 = {1, 2, 3, 4, 5, 6} set2 = {4, 5, 6, 7, 8, 9} set1 |= set2 print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9} set1 = {1, 2, 3, 4, 5, 6} set2 = {4, 5, 6, 7, 8, 9} set3 = {10, 11} set1.update(set2, set3) print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} set1 = {1, 2, 3, 4, 5, 6} set2 = {4, 5, 6, 7, 8, 9} set3 = {10, 11} set1 |= set2 | set3 print(set1) # wynik --> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}