Python - Join Sets
پرش به ناوبری
پرش به جستجو
Join Two Sets
There are several ways to join two or more sets in Python.[۱]
You can use the union()
method that returns a new set containing all items from both sets, or the update()
method that inserts all the items from one set into another:
Note: Both
union()
and update()
will exclude any duplicate items.Keep ONLY the Duplicates
The intersection_update()
method will keep only the items that are present in both sets.
The intersection()
method will return a new set, that only contains the items that are present in both sets.
Keep All, But NOT the Duplicates
The symmetric_difference_update()
method will keep only the elements that are NOT present in both sets.
The symmetric_difference()
method will return a new set, that contains only the elements that are NOT present in both sets.
منابع آموزشی