add vs update in set operations in python

前端 未结 9 619
天涯浪人
天涯浪人 2020-12-07 18:30

What is the difference between add and update operations in python if i just want to add a single value to the set.

a = set()
a.update([1]) #works
a.add(1) #         


        
9条回答
  •  爱一瞬间的悲伤
    2020-12-07 18:54

    We use add() method to add single value to a set.

    We use update() method to add sequence values to a set.

    Here Sequences are any iterables including list,tuple,string,dict etc.

提交回复
热议问题