Python Sets

Sets are collection of immutable elements with NO duplicate values.

A Set CANNOT contain mutable elements like list, dictionary, and sets.

A Set CAN contain immutable elements like, numbers, strings, and tuples.

Sets are commonly used to remove duplicate values from a collection of values in a list or tuple.

You can create a set by using the curly braces { } and putting elements separated by commas.

Sample Output

How to create a python set
How to create a python set


Sets does not support indexing

Sets cannot be iterated because they does not support indexing.

Sample Output

Python Sets does not support indexing
Python Sets does not support indexing


Using set to Remove duplicate values

Python sets are frequently used to remove duplicate values from a list or tuple.

Sample Output

Removing duplicate values using a set
Removing duplicate values using a set


Common set commands

Sets are used primarily to get comparison between two set of values. Sets are built for the operations like intersection, union etc.

Sample Output

Common set commands in python
Common set commands in python

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

Leave a Reply!

Your email address will not be published. Required fields are marked *