- add() is a python function for the set data type.
- it add new item in the set.
Syntax-
set.add(item)
Example
set is {1,2,3}
set.add(4) will give {1,2,3,4}
set.add([1,2,3]) will give an error, because add() function can add only single element data type like int or string, not the list or set.
program-
s1=set([1,2,3])
print(s1)
s1.add(7)
print(s1)
s1.add(4)
print(s1)
s1.add("one")
print(s1)
s1.add("two")
print(s1)
{1, 2, 3}
{1, 2, 3, 7}
{1, 2, 3, 4, 7}
{1, 2, 3, 4, 7, 'one'}
{1, 2, 3, 4, 7, 'one', 'two'}