Python Set metoda add()
Příklad
Přidejte prvek do fruits
sady:
fruits =
{"apple", "banana", "cherry"}
fruits.add("orange")
print(fruits)
Definice a použití
Metoda add()
přidá prvek do množiny.
Pokud prvek již existuje, add()
metoda prvek nepřidá.
Syntax
set.add(elmnt)
Hodnoty parametrů
Parameter | Description |
---|---|
elmnt | Required. The element to add to the set |
Další příklady
Příklad
Zkuste přidat prvek, který již existuje:
fruits = {"apple", "banana", "cherry"}
fruits.add("apple")
print(fruits)