In Python, you can add elements to a set using add()
or update()
. The add()
method adds one item, while update()
can add multiple items from iterable objects.
Python में set में items जोड़ने के लिए add()
और update()
methods का उपयोग होता है। add()
एक item जोड़ता है जबकि update()
कई items को एक साथ जोड़ता है।
add()
fruits = {"apple", "banana"}
fruits.add("mango")
print(fruits)
update()
fruits.update(["orange", "grape"])
print(fruits)
set1 = {"apple", "banana"}
set2 = {"kiwi", "melon"}
set1.update(set2)
print(set1)
chars = {"a", "b"}
chars.update("xyz")
print(chars)
nums = {1, 2}
nums.update((3, 4))
print(nums)