update() set function in python by R4R Team

- update() is a python function which is update or add new items in the given set.

Syntax-

set.update(list)

-Here list shows the items whicbh are add on the set.

Example
set is {1,2,3}
set.update([4]) will give {1,2,3,4}


program-

s=set([1,2,3])
print("Set is ",s)

s.update([4])
print("Set is",s)

s.update([5,6,"one","two"])
print("Now set is",s)


output-

Set is {1, 2, 3}
Set is {1, 2, 3, 4}
Now set is {1, 2, 3, 4, 5, 6, 'one', 'two'}


-In this program, we have a set {1,2,3} then firstly we pass [4] in update so set become {1,2,3,4}, then further we pass a list [5,6,"one","two"] in update() function so set is finially become {1, 2, 3, 4, 5, 6, 'one', 'two'}.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!