The document outlines various built-in methods for Python sets, including their functions and usage. Key methods include 'add', 'clear', 'copy', 'difference_update', and 'union', among others, each serving specific purposes for set manipulation. These methods allow for adding, removing, and comparing elements within sets.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
8 views2 pages
Python
The document outlines various built-in methods for Python sets, including their functions and usage. Key methods include 'add', 'clear', 'copy', 'difference_update', and 'union', among others, each serving specific purposes for set manipulation. These methods allow for adding, removing, and comparing elements within sets.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Python Built in set methods
Python contains the following methods to be used with the sets.
SN METHOD Description 1. Add (item) It adds an item to the set . It has no effect if the item is already present in the set.
2. Clear() It deletes all the items from the set.
3. Copy() It returns a shallow copy of the set. 4. Difference_update (…) It modifies this set by removing all the items that are also present in the specified sets. 5. Discard(item) It removes the specified item from the set. 6. Intersection() It returns a new set that contains only the common elements of both the sets. (all the set if more than two are specified). 7. Intersection_update(…) It removes the items from the original set that are not present in both the sets. (all the sets if more than two are specified. 8. Isdisjoint(…) Return True if two sets have a null intersection. 9. Issubset(…) Report whether another set contains this set. 10. Issuperset(…) Report whether this set contains another set. 11. Pop() Remove and return an arbitrary set element that is the last element of the set. Raises KeyError if the set is empty. 12. remove(item) Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError. 13. symmetric _difference(…) Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError. 14. symmetric _difference_update(…) Update a set with the symmetric difference of itsself and another. 15. Union(…) Return the union of sets as a new set (i.e. all element that are in either set.) 16. Update() Update a set with the union of itself and others.