0% found this document useful (0 votes)
2 views41 pages

14.python - Sets

The document provides an overview of sets in Python, detailing their characteristics such as being unordered, unchangeable, and not allowing duplicate values. It covers various operations on sets, including adding, removing, and joining sets, as well as using set operators for intersection, difference, and symmetric difference. Additionally, it includes examples to illustrate these concepts.
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)
2 views41 pages

14.python - Sets

The document provides an overview of sets in Python, detailing their characteristics such as being unordered, unchangeable, and not allowing duplicate values. It covers various operations on sets, including adding, removing, and joining sets, as well as using set operators for intersection, difference, and symmetric difference. Additionally, it includes examples to illustrate these concepts.
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 - Sets

Sets
• A set is one of the built-in data types in Python.

• Set items are unordered, unchangeable, and do not allow


duplicate values.

• Objects in a set can be of any data type.

• A set object is a collection of one or more immutable


objects enclosed within curly brackets {}.
Example
Access Set Items
Check Set Item Exists
Add Set Items
update() Method
Unique Set
Example
Remove Set Items Ignoring Error
Example
Remove Random Item from Set
Remove All Set
Remove Items that Exist in Both Sets
The difference_update() method in set class updates the set by
removing items that are common between itself and another set given
as argument.
Example
Example
Remove Uncommon Set Items
Example
Python - Join Sets
Join Python Sets Using "|" Operator
Join Python Sets union() Method
Join Python Sets update() Method
Join Python Sets Using Unpacking Operator
Python - Copy Sets
Python Copy Sets
Example
Python - Set Operators
Example
Python Set Intersection Operator (&)
Example
Python Set Difference Operator (-)
Example
Python Set Symmetric Difference Operator
Example
Find Maximum and the Minimum
value in a set
Comparison Operators
Check if a specific value exists
Create a set of words with their characters
repeated twice
Create a set of non-whitespace characters from
a string
Thank You

You might also like