Good day.
I am learning Python by video lectures, I have reached sets, the example mentions the union method
a.union and
a.update What is the fundamental difference?
Good day.
I am learning Python by video lectures, I have reached sets, the example mentions the union method
a.union and
a.update What is the fundamental difference?
union as a result returns a new set without changing the source, and update returns nothing, but adds elements of the second to the first set.
>>> a = set([1,2,3]) >>> b = set([2,3,4]) >>> print a.union(b) set([1, 2, 3, 4]) >>> print a set([1, 2, 3]) >>> print b set([2, 3, 4]) >>> a = set([1,2,3]) >>> b = set([2,3,4]) >>> print a.update(b) None >>> print a set([1, 2, 3, 4]) >>> print b set([2, 3, 4]) Source: https://ru.stackoverflow.com/questions/392293/
All Articles