Sets
You will learn about the set object in Python in this lesson.
We'll cover the following...
We'll cover the following...
Definition
A set is a collection of values that are not necessarily all the same type. To write a set, use braces around a comma-separated list. Take a look at a few examples using sets below:
Empty set
In Python, an empty set (one with no elements) cannot be written as {}. Instead, the set() function is used.
Set properties
Sets have two important properties:
- Sets have no duplicate elements. A value is either in the set, or it is not in the set. Sets provide the
inandnot inoperators which allow us to check duplicates.
- The order of elements in a set is unspecified, so you cannot index