add() method for set

All set methods

add(element) takes one arguments .

element : element to be added to set
Returns : No return value.
my_set={'Alex','Ronald','John'}
my_set.add('Lewis')
print(my_set)
Output is here
{'Ronald', 'John', 'Alex', 'Lewis'}
Adding duplicate value
my_set={'a','b','c','x'}
my_set.add('c')
print(my_set)
Output
{'a', 'x', 'c', 'b'}
There is no error if we try to add element already available but it will not add the element again as set can't have duplicate elements.

Difference between add() and update()

Read more on update() method here.
All set methods Questions with solutions on set


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer