Programming with Python Quiz
Questions: 16 · 10 minutes
1. Given palette = (""red"", ""green""), which statement creates a new tuple containing ""blue"" while leaving palette unchanged?
palette.append(""blue"")
expanded = list(palette).append(""blue"")
palette[2] = ""blue""
expanded = palette + (""blue"",)
2. Which condition uses Python’s identity test to check specifically for the singleton value None?
result is None
result = None
not result
type(result) is null
3. In Python 3, what is the data type of the value 3.5?
float
int
decimal
str
4. What does bool({}) evaluate to in Python?
True, because a dictionary object exists
False, because the dictionary is empty
None, because the dictionary has no entries
An error, because dictionaries cannot become Boolean values
5. What is the result of the expression ""7"" + ""3""?
The string ""73""
The string ""10""
An error because strings cannot use +
The integer 10
6. Which built-in Python collection is mutable?
tuple
frozenset
list
str
7. In Python 3, what are the value and type of 5 / 2?
2 with type int
2.5 with type float
2.0 with type float
2.5 with type decimal
8. What value is produced by 7 // 2?
3
4
1
3.5
9. What is the result of {1, 1, 2} == {1, 2}?
A TypeError, because sets cannot be compared
False, because the left side originally contains three entries
False, because sets compare insertion order
True, because duplicate set entries are not retained
10. What does this code print?
first = [1, 2]
second = first
second.append(3)
print(first)
[1, 2], because append affects only second
[1, 2, 3], because both names refer to the same list
[3], because append replaces the original values
An error, because lists cannot be assigned to two names
11. What value is assigned to total?
total = int(""12"") + 3
The string ""123""
A TypeError caused by mixing a string and an integer
The integer 15
A ValueError caused by converting ""12""
12. What does this code print?
tags = {""python"", ""quiz"", ""python""}
print(len(tags))
3, because three values were entered
1, because all values have the same data type
An error, because sets cannot contain strings
2, because a set keeps unique values
13. What does this code print?
profile = {""age"": 30}
profile[""age""] += 1
print(profile[""age""])
30
The string ""301""
A KeyError
31
14. What is the result of letters[1:4] when letters = ""abcdef""?
""abc""
""bcd""
""bcde""
""cde""
15. What does this code print?
a, b = (4, 9)
print(a + b)
(4, 9)
The string ""49""
13
An error because tuples cannot be unpacked
16. Which value can be used as a dictionary key in Python?
A list containing ""north"" and ""south""
A set containing ""north"" and ""south""
A tuple containing ""north"" and ""south""
A dictionary mapping ""region"" to ""north""