You are on page 1of 1

Set Methods

Sets are unordered & mutable collections of


unique elements

add clear copy


Add an element to Set. Will not add if element Remove all elements in set Return copy of set
already exists

difference difference_update discard


Return set with difference between two sets. Same as difference but removes unwanted Remove item from set. Will not throw error if
i.e. exist only in the first set & not in both sets items instead of returning new set item doesn't exist

intersection intersection_update isdisjoint


Return set containing only items that exist in Same as intersection but removes unwanted Return True if none of the items are in
all sets. Can pass multiple parameters items instead of returning new set both sets

issubset issuperset pop


Return True if all items in original set Return True if all items in specified set Remove and return random item from set
exist in specified set exist in original set

remove symmetric_difference symmetric_difference_update


Same as discard but will raise error if item Return set containing all items from both Same as symmetric_difference but updates the
does not exist sets, but not those present in both sets original set rather than returning new one

union update
Return set containing items from original set & Update original set by adding items from
items from specified set(s) or iterable(s) another set or iterable

Reference Feel Free to


Buy Me A
W3Schools.com Coffee
By @AbzAaron

You might also like