An unordered collection with no duplicates: adding and removing elements, iterating, union, intersection and difference, and testing whether one set sits inside another.
No account needed to read a lesson · 30-day money-back guarantee
See the full learning path6
lessons
49
practice questions
44
prerequisite lessons
1 of the 6 lessons here is free to preview - the whole explanation and worked example, with no account and no email.
The editor you get
A still of the editor, not a live one
Python Editor
Editor Output
Output:
{1, 2, 3, 4} {3}
You write and run Python in the browser - nothing to install, no setup. Questions are marked on the values your code produces. The snippet here is an example of the kind of code you write.
The 6 lessons in this unit. Expand any one to see what it covers. Each unlocks when its own prerequisites are passed.
01
Sets
12 questions
Understand the unique, unordered nature of Python sets, how to create them from various iterables, and how to determine their size using the len() function.
Covers
Sets overview
Creating a set
Length of a set
02
Add and remove elements from a set
8 questions
Learn how to add elements to a set and remove them using .remove() or .discard(), understanding how each method handles missing elements and duplicates.
Covers
Add elements to a set
Remove elements from a set
03
Iterating over a set
4 questions
Learn how to use a for loop to access each element in a Python set, noting that the elements may appear in any order due to the set's unordered nature.
Covers
Iterating over a set
04
Set union, intersection and difference
12 questions
Learn how to use the union, intersection and difference operations to combine, compare and subtract sets in Python using both methods and operators.
Covers
Set union
Set intersection
Set difference
05
Subsets and supersets
8 questions
Learn how to determine whether one set is a subset or superset of another, including proper subsets and supersets, and use Python operators to perform these set comparisons.
Covers
Subsets
Supersets
06
Activity: nature reserve
5 questions
Practise using Python lists and sets to track unique animal species, update records, find overlaps and differences between groups, and perform calculations with animal data in a nature reserve context.
Covers
Unique animals
Update animals in Zone A
Shared species
High-priority species
Weighing the animals
This unit is part of our Python Done Right learning path, which contains 100 lessons. Every one of them is drawn below.
The diagnostic test lets you skip any lesson you already know, including the ones in this unit.
Hover any dot to name its lesson.
6 lessons in this unit
44 prerequisite lessons across the unit, counting every step back to the start
50 other lessons in the learning path - after this unit, or alongside it
Builds on: Assorted extras, Comparisons, Dictionaries
Leads to: Assorted extras, Comparisons, Comprehensions, User-defined functions
One subscription covers every learning path, and you can test out of anything you already know.
One subscription covers every learning path · 30-day money-back guarantee
More in Data structures: Lists, Tuples, Dictionaries