Q:

add element in set python

yourset = set([1,2,3])
yourset.add(4)
9
# Basic syntax:
your_set.add(element)

# Example usage:
your_set = {'all', 'kinds', 'of', 'stuff'}
your_set.add('wacky')
print(your_set)
--> {'of', 'all', 'kinds', 'stuff', 'wacky'}
2
thisset = {"apple", "banana", "cherry"}

thisset.add("orange")

print(thisset)
4
list1 = [1, 1, 2, 3, 4, 4, 5]
set1 = set(list1)
set1.add(6)			# gets inserted in the set if it does not already exist
set1.add(5)			# gets ignored as it already exists in the set
2
# set of letters 
GEEK = {6, 0, 4} 
  
# adding 1 
GEEK.add(1) 
print('Letters are:', GEEK) 
  
# adding 0  
GEEK.add(0) 
print('Letters are:', GEEK) 
0

New to Communities?

Join the community