Advertisements
Advertisements
प्रश्न
List out the set operations supported by python.
थोडक्यात उत्तर
Advertisements
उत्तर
The python supports the set operations such as
Union, Intersection, Difference, and Symmetric difference.
Union:
- The union includes all elements from two or more sets.
- In python, the operator | (pipeline) is used to the union of two) sets.
- The function union() is also used to join two sets in python.
Intersection:
- Intersection includes the common elements in two sets.
- The operator & is used to intersect two sets in python.
- The function intersection() is also used to intersect two sets in python.
Difference:
- The difference includes all elements that are in the first set (say set A) but not in the second set (say set B).
- The minus (-) operator is used to difference set operation in python.
- The function difference() is also used to difference operation.
Symmetric difference:
- The symmetric difference includes all the elements that are in two sets (say sets A and B) but not the ones that are common to two sets.
- The caret (A) operator is used for the symmetric difference set operation in python.
- The function symmetric_difference() is also used to do the same operation.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
