طريقة إضافة Python Set ()
مثال
أضف عنصرًا إلى 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)