Max
0
Q:

python how to add elements to a set

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
# 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