0% found this document useful (0 votes)
10 views1 page

Python Set Functions Overview

The document provides a comprehensive overview of Python's built-in set functions, detailing their descriptions, syntax, and examples. Key functions include add(), update(), remove(), and various operations for set manipulation such as intersection, union, and difference. Each function is illustrated with a practical example to demonstrate its usage.

Uploaded by

venkatasai012345
Copyright
© All Rights Reserved
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% found this document useful (0 votes)
10 views1 page

Python Set Functions Overview

The document provides a comprehensive overview of Python's built-in set functions, detailing their descriptions, syntax, and examples. Key functions include add(), update(), remove(), and various operations for set manipulation such as intersection, union, and difference. Each function is illustrated with a practical example to demonstrate its usage.

Uploaded by

venkatasai012345
Copyright
© All Rights Reserved
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

Python Built-in Set Functions

Function Description Syntax Example

add() Adds an element to the set [Link](item) {1, 2}.add(3) -> {1, 2, 3}

update() Adds multiple elements to the set [Link](iterable) {1, 2}.update([3, 4]) -> {1, 2, 3, 4}

copy() Returns a shallow copy of the set [Link]() s = {1, 2}; [Link]() -> {1, 2}

remove() Removes an element (error if not found) [Link](item) {1, 2, 3}.remove(2) -> {1, 3}

discard() Removes an element (no error if missing) [Link](item) {1, 2, 3}.discard(2) -> {1, 3}

pop() Removes and returns an arbitrary element [Link]() {1, 2, 3}.pop() -> 1, {2, 3}

clear() Removes all elements from the set [Link]() {1, 2, 3}.clear() -> {}

difference() Returns difference of sets [Link](set2) {1, 2, 3}.difference({2}) -> {1, 3}

difference_update() Updates set with difference set.difference_update(set2) {1, 2, 3}.difference_update({2}) -> {1, 3

symmetric_difference() Returns elements in either set but not bothset.symmetric_difference(set2) {1, 2, 3}.symmetric_difference({2, 4}) ->

symmetric_difference_update()
Updates set with symmetric difference set.symmetric_difference_update(set2)
{1, 2, 3}.symmetric_difference_update(

intersection() Returns intersection of sets [Link](set2) {1, 2, 3}.intersection({2, 3}) -> {2, 3}

intersection_update() Updates set with intersection set.intersection_update(set2) {1, 2, 3}.intersection_update({2, 3}) -> {

union() Returns union of sets [Link](set2) {1, 2}.union({2, 3}) -> {1, 2, 3}

isdisjoint() Checks if sets have no elements in common


[Link](set2) {1, 2}.isdisjoint({3, 4}) -> True

issubset() Checks if set is a subset [Link](set2) {1, 2}.issubset({1, 2, 3}) -> True

issuperset() Checks if set is a superset [Link](set2) {1, 2, 3}.issuperset({1, 2}) -> True

You might also like