Sets

Understand the variations of sets in Python.

This lesson lists different implementations of a set provided by Python 3 and explains when to use which built-in support.

Introduction

A set is a collection of items that does not allow duplicates. It’s an unordered collection.

⚠️ Note: In case you forget, the expression of a set involves curly-braces {} in Python. To create an empty set, we call the set() function. Using {} without any values in it will create a dictionary, not a set.

Types of sets

Mutable set with set

The set() creates a mutable structure. Operations like dynamic insertion and deletion are allowed. Python provides basic sets’ operations, like intersection and union.

Run the following program to have an overview.

Get hands-on with 1400+ tech skills courses.