पायथन सेट ऐड () विधि
उदाहरण
सेट में एक तत्व जोड़ें fruits
:
fruits =
{"apple", "banana", "cherry"}
fruits.add("orange")
print(fruits)
परिभाषा और उपयोग
विधि सेट में add()
एक तत्व जोड़ती है।
यदि तत्व पहले से मौजूद है, तो add()
विधि तत्व को नहीं जोड़ती है।
वाक्य - विन्यास
set.add(elmnt)
पैरामीटर मान
Parameter | Description |
---|---|
elmnt | Required. The element to add to the set |
और ज्यादा उदाहरण
उदाहरण
एक तत्व जोड़ने का प्रयास करें जो पहले से मौजूद है:
fruits = {"apple", "banana", "cherry"}
fruits.add("apple")
print(fruits)