C. Set Methods

This appendix lists the methods of the set type. It does not cover functions that also may be used with this type, such as len. For those, see Appendix B.

Table C.1. Most Commonly Used Set Methods.

To do the following task:

Call these method(s):

Add element to a set


Clear all contents of a set


Copy all contents of another set


Delete an item from a set

discard, pop, remove

Determine if set is a subset or superset of another

issubset, issuperset

Perform set difference (set subtraction)


Perform intersection


Perform union


Note: To determine if an element is a member of a particular set, use the in keyword.


Adds an object,

Get Supercharged Python: Take Your Code to the Next Level, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.