How to Create a Set in Python: Methods, Syntax, and Use Cases

Python sets are one of the language's most useful but often overlooked built-in data structures. If you've been relying on lists for everything, understanding sets can meaningfully change how you write cleaner, faster code — especially when uniqueness and membership testing matter.

What Is a Set in Python?

A set is an unordered collection of unique elements. Three properties define it:

  • Unordered — items have no index or guaranteed position
  • Unique — duplicate values are automatically removed
  • Mutable — you can add or remove items after creation (with one exception: frozen sets)

Sets are particularly efficient for operations like checking whether a value exists in a collection, removing duplicates from a list, or performing mathematical set operations like unions and intersections.

The Two Main Ways to Create a Set

1. Using Curly Braces {}

The most direct syntax: