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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.