This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Variables and Types, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
Which value is a float?
Answer: 3.0
Why: A float is a number with a decimal point, even when the decimal part is zero.
What does type(True).__name__ return?
Answer: bool
Why: True and False are values of the built-in bool type.
Which variable name is valid in Python?
Answer: order_total
Why: A variable name may contain letters, digits, and underscores, but cannot start with a digit or be a keyword.
What appears on the screen?
price = 4
quantity = 3
print(price * quantity)Answer: 12
Why: price * quantity multiplies 4 by 3.
Complete the expression so total is price multiplied by quantity.
total = price ____ quantityAnswer: *
Why: The asterisk is Python's multiplication operator.
Complete the assignment to store the boolean value true.
is_member = ____Answer: True
Why: Python's boolean true value starts with a capital T.
Complete the attribute so the expression evaluates to int.
print(type(42).____)Answer: __name__
Why: type(value).__name__ returns the type name as a string.
Complete the format spec so the price shows two decimal places.
price = 4.5
print(f"{price:____}")Answer: .2f
Why: The f-string format spec .2f displays two digits after the decimal point.
What is printed?
x = 5
y = 3
print(x + y)Answer: 8
Why: 5 + 3 is 8.
What is the output?
print(type(3.0).__name__)Answer: float
Why: 3.0 is a float.
What does this code print?
print(int("12") + 3)Answer: 15
Why: int("12") converts the text to 12, then adds 3.
What does the program output?
print(10 / 4)Answer: 2.5
Why: True division always returns a float in Python 3.
Try the questions first
Open the practice page for Python Variables and Types and answer the same 12 questions with instant feedback.