1/15
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Is a Python set considered immutable or mutable?
Python set is a mutable data type.
What is the syntax for creating an empty set in Python?
You must use the set() constructor. Ex: set_name = set()
What is the syntax for creating a non-empty set in Python?
Use curly braces with values inside separated by commas. Ex: set_name = {value, value_1, value_2}
Do Python sets preserve insertion order?
No, Python sets do not preserve insertion order as they are unordered and unindexed.
Can Python sets contain duplicate values?
No, Python sets cannot contain duplicate values.
What types of values can Python sets contain?
Python sets can only contain immutable/hashable object types, including ints, floats, strings, booleans, tuples, and frozensets.
Can a Python set be indexed?
No, Python sets cannot be indexed.
How can you add an element to a Python set?
Use the .add() or .update() method. Ex: set_name.add(value) or set_name.update(other_iterable)
How can you add multiple items to a Python set?
Use the .update() method, passing in any iterable object. Ex: set_name.update(other_iterable)
Can you add an element to a specific index in a Python set?
No, you cannot insert elements at a specific index because sets are unordered and unindexed.
How do you remove an element in a Python set that won't raise an error if the item doesn't exist?
Use the .discard() method. Ex: set_name.discard(value)
How do you remove an element in a Python set that will raise an error if the item doesn't exist?
Use the .remove() method. Ex: set_name.remove(value)
How do you remove a random item in a Python set?
Use the .pop() method. Because sets are unordered, it will remove and return an arbitrary item. Ex: set_name.pop()
How do you delete a Python set entirely?
Use the del keyword. Ex: del set_name
How do you copy a Python set?
Use the .copy() method. Ex: new_set = set_name.copy()
How do you check if