I have these two source code and I do not understand the difference
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.symmetric_difference(y)
print(z) ## z now is {'google', 'cherry', 'microsoft', 'banana'}
and
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = (x - y).update((y - x))
print(z) ## z now is NoneType
why the second code does not result in as the first one? as I know, (x-y) will return a set, then I apply update method with (y - x) to merge (x-y) set and (y-x), so the results should be same?
With a small change it will work:
Update operation is in-place, so for the expression you use
x-y
ends up being temporary set value which is updated in-place. Therefore, assignment ends up beingNone
.