Python TutorialLesson 16Free preview
Python Sets
This lesson is part of Python · All levels
Summary
A set is a unique collection of elements without a guarantee of order, so it is very useful for removing duplicates and checking membership quickly. Elements are written in curly braces with a comma separator, while empty sets must be made with set(). Python provides mathematical operations such as union, intersection, and difference to compare two sets.
Key points
- The set only keeps unique and unordered elements.
- The empty set is made with set(), not {} meaning dictionary.
- The method is used to manage the elements.
- The operations union (), intersection (&), and difference (-) compare sets.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.