0
0
Pythonprogramming~5 mins

Set creation in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A{}
Bset([])
C[]
Dset()
What will be the output of {1, 2, 2, 3}?
A{1, 2, 3}
B{1, 2, 2, 3}
C[1, 2, 3]
D(1, 2, 3)
Which of these can be an element of a set?
A(1, 2)
B{1: 'a'}
C[1, 2]
D{1, 2}
What type of collection is a set?
AUnordered and allows duplicates
BUnordered and no duplicates
COrdered and allows duplicates
DOrdered and no duplicates
How do you create a set from a list [1, 2, 3]?
A[1, 2, 3].set()
B{[1, 2, 3]}
Cset([1, 2, 3])
Dset{1, 2, 3}
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.