set : set to be added to main setmy_set={'a','b','c','x'}
my_set2={'x','y','z'}
my_set.update(my_set2)
print(my_set)
Output is here
{'z', 'a', 'x', 'y', 'b', 'c'}
In above code x is added once only as no duplicate value is kept.
my_set={'a','b','c','x'}
str='alex'
my_set.update(str)
print(my_set)
Output
{'a', 'b', 'c', 'x', 'l', 'e'}
my_set={'a','b','c','x'}
my_list=['x','y','z']
my_set.update(my_list)
print(my_set)
Output
{'z', 'a', 'y', 'b', 'x', 'c'}
my_set={'a','b','c','x'}
my_tuple=('x','y','z')
my_set.update(my_tuple)
print(my_set)
Output
{'z', 'a', 'y', 'b', 'x', 'c'}
There is no error if we try to add element already available but it will not update the element again as set can't have duplicate elements.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.