Recall & Review
beginner
What is a set in Python?
A set is a collection of unique items. It does not keep order and does not allow duplicates.
Click to reveal answer
beginner
How do you create an empty set in Python?
Use
set(). Using {} creates an empty dictionary, not a set.Click to reveal answer
beginner
Which of these creates a set with elements 1, 2, and 3?
1) {1, 2, 3}
2) set([1, 2, 3])
3) {1, 2, 2, 3}
4) set()Options 1, 2, and 3 all create a set with elements 1, 2, and 3. Option 3 has a duplicate 2, but sets remove duplicates automatically.
Click to reveal answer
intermediate
Can sets contain mutable items like lists?
No. Sets can only contain immutable (unchangeable) items like numbers, strings, or tuples.
Click to reveal answer
beginner
What happens if you try to create a set with duplicate elements?
Duplicates are automatically removed. The set will only keep one copy of each unique element.
Click to reveal answer
Which syntax creates an empty set in Python?
✗ Incorrect
Only set() creates an empty set. {} creates an empty dictionary.
What will be the output of
{1, 2, 2, 3}?✗ Incorrect
Sets remove duplicates automatically, so only unique elements remain.
Which of these can be an element of a set?
✗ Incorrect
Tuples are immutable and can be set elements. Lists and dictionaries are mutable and cannot.
What type of collection is a set?
✗ Incorrect
Sets are unordered collections that do not allow duplicate elements.
How do you create a set from a list
[1, 2, 3]?✗ Incorrect
Use set() with the list as argument to create a set from it.
Explain how to create a set in Python and what makes sets different from lists.
Think about curly braces and the set() function.
You got /4 concepts.
Describe what types of elements can be added to a set and why some types are not allowed.
Consider what it means for an object to be unchangeable.
You got /3 concepts.