bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Python/Reference and Practice
Python•Reference and Practice

Python Set Methods

Python has a set of built-in methods that you can use on sets.

MethodShortcutDescription
add()Adds an element to the set
clear()Removes all the elements from the set
copy()Returns a copy of the set
difference()-Returns a set containing the difference between two or more sets
difference_update()-=Removes the items in this set that are also included in another, specified set
discard()Remove the specified item
intersection()&Returns a set, that is the intersection of two other sets
intersection_update()&=Removes the items in this set that are not present in other, specified set(s)
isdisjoint()Returns whether two sets have a intersection or not
issubset()<=Returns True if all items of this set is present in another set
<Returns True if all items of this set is present in another, larger set
issuperset()>=Returns True if all items of another set is present in this set
>Returns True if all items of another, smaller set is present in this set
pop()Removes an element from the set
remove()Removes the specified element
symmetric_difference()^Returns a set with the symmetric differences of two sets
symmetric_difference_update()^=Inserts the symmetric differences from this set and another
union()Return a set containing the union of sets
update()=Update the set with the union of this set and others

Learn more about sets in our Python Sets Tutorial .

Previous

Python Tuple Methods

Next

Python File Methods

This chapter

Overview
11

Lessons

35m

Read time

1. Python Built in Functions2. Python Interview Questions3. Python String Methods4. Python List/Array Methods5. Python Dictionary Methods6. Python Tuple Methods7. Python Set Methods8. Python File Methods9. Python Keywords10. Python Built-in Exceptions11. Python Glossary