Recall & Review
beginner
What is a frozen set in Python?
A frozen set is an immutable version of a set. Once created, you cannot add or remove elements from it.
Click to reveal answer
beginner
Can you add elements to a frozen set after it is created?
No, frozen sets are immutable, so you cannot add or remove elements after creation.
Click to reveal answer
intermediate
How do frozen sets behave when used as dictionary keys?
Frozen sets can be used as dictionary keys because they are immutable and hashable, unlike regular sets.
Click to reveal answer
beginner
What happens if you try to call add() on a frozen set?
You get an AttributeError because frozen sets do not support methods that modify the set, like add() or remove().
Click to reveal answer
beginner
How can you create a frozen set from a list?
Use the frozenset() function and pass the list as an argument, for example: frozenset([1, 2, 3]).
Click to reveal answer
Which of the following is true about frozen sets?
✗ Incorrect
Frozen sets are immutable and hashable, so they can be used as dictionary keys. They do not support modification methods like add().
What error do you get if you try to add an element to a frozen set?
✗ Incorrect
Calling add() on a frozen set raises an AttributeError because frozen sets do not have this method.
How do you create a frozen set from a list named my_list?
✗ Incorrect
Use frozenset(my_list) to create an immutable frozen set from the list.
Which method is NOT supported by frozen sets?
✗ Incorrect
Frozen sets do not support add() because they are immutable, but they support union(), intersection(), and difference().
Why can frozen sets be used as dictionary keys but regular sets cannot?
✗ Incorrect
Only immutable and hashable objects can be dictionary keys. Frozen sets are immutable and hashable, unlike regular sets.
Explain what a frozen set is and how it differs from a regular set.
Think about what 'frozen' means in real life.
You got /4 concepts.
Describe a situation where using a frozen set would be better than a regular set.
Consider when you want to keep a collection fixed and safe.
You got /3 concepts.