Question | Click to View Answer |
What does the following code print to the console? n = {1, 10, 4}
print(type(n))
|
Sets are unordered collections of unique items. Sets cannot contain duplicate items. Both sets and dictionaries are enclosed by curly braces ( |
What does the following code print to the console? n = {1, 1, 1, 20, 30}
print(n)
|
Sets cannot have duplicates. Python will automatically remove the duplicate items when creating a set. |
What does the following code print to the console? stuff = {"a", 8, "cat"}
stuff.add("dog")
print(stuff)
|
The |
What does the following code print to the console? nums = {1, 2, 3}
nums.add(3)
print(nums)
|
Sets only contain unique values, so the |
What does the following code print to the console? things = {"paper", "rock", "bottle"}
things.discard("bottle")
print(things)
|
The |
What does the following code print to the console? games = {"mariocart", "zelda", "splatoon"}
print(games[0])
|
This code raises a TypeError with the following message: 'set' object does not support indexing. Sets are unordered, so they can't be indexed. Dictionaries are also unordered and cannot be indexed. Lists are ordered and can be indexed. |
What does the following code print to the console? sports = {"hockey", "golf"}
print("golf" in sports)
|
The |
What does the following code print to the console? a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a.union(b))
|
The |
What does the following code print to the console? a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a.intersection(b))
|
The |
What does the following code print to the console? a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a.difference(b))
|
The
|
What does the following code print to the console? a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a.symmetric_difference(b))
|
The The Notice that |