0Pricing
Python Academy · Lesson

Sets and Set Operations

Build sets and perform union, intersection, and difference.

Introduction

Sets are unordered collections of unique hashable elements. They are optimized for membership testing and mathematical set operations.

Creating a Set

s = {1, 2, 3} or s = set([1, 2, 2, 3]) — duplicates are removed automatically. {} creates an empty DICT, not a set.
s = {1, 2, 2, 3}
print(s)  # {1, 2, 3}
empty = set()
print(type(empty))

All lessons in this course

  1. Dictionary Basics
  2. Dictionary Methods
  3. Sets and Set Operations
  4. Dictionary Comprehensions
← Back to Python Academy