Python Set metoda add()
Przykład
Dodaj element do fruits
zestawu:
fruits =
{"apple", "banana", "cherry"}
fruits.add("orange")
print(fruits)
Definicja i użycie
Metoda add()
dodaje element do zestawu.
Jeśli element już istnieje, add()
metoda nie dodaje elementu.
Składnia
set.add(elmnt)
Wartości parametrów
Parameter | Description |
---|---|
elmnt | Required. The element to add to the set |
Więcej przykładów
Przykład
Spróbuj dodać element, który już istnieje:
fruits = {"apple", "banana", "cherry"}
fruits.add("apple")
print(fruits)