0Pricing
Learn AI with Python · Lesson

Sets

Discover how to use sets for operations involving unique elements.

1

Introduction to Sets

Sets are unordered collections of unique items in Python. They are useful when you need to store unique elements and perform set operations like union, intersection, and difference.

In this lesson, you’ll learn how to create and manipulate sets, and perform common set operations.

Sets — illustration 1

2

Creating Sets

A set is created by placing items inside curly braces {}, separated by commas. For example:

# Creating a set
fruits = {"apple", "banana", "cherry"}
print(fruits)

All lessons in this course

  1. Lists
  2. Tuples
  3. Sets
  4. Dictionaries
  5. Strings as Data Structures
← Back to Learn AI with Python