This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Print and Strings, 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 call prints two values separated by a space?
Answer: print("Latte", 4.5)
Why: print() accepts multiple arguments and puts a space between them by default.
Which string correctly inserts the value of name into the message?
Answer: f"Hello, {name}"
Why: An f-string uses curly braces to evaluate the variable inside the text.
What does print("A", "B", sep="-") display?
Answer: A-B
Why: sep replaces the default space between the two values.
Which literal creates a string that can span multiple lines?
Answer: A triple-quoted string
Why: Triple quotes allow a string literal to include line breaks.
Replace the blank so the two words are separated by a hyphen.
print("Hello", "Python", sep="____")Answer: -
Why: sep is the separator placed between arguments.
Complete the f-string so the output is Hello, Maya!
name = "Maya"
print(f"Hello, ____!")Answer: {name}
Why: Curly braces insert the value of name into an f-string.
Complete the format spec so the price shows two decimal places.
price = 4.5
print(f"Total: ${price:____}")Answer: .2f
Why: The .2f format spec rounds a float to two decimal places.
Complete the escape sequence that creates a new line inside the string.
print("line1____line2")Answer: \n
Why: The two-character escape \n starts a new line when printed.
What is printed?
print("Hello, Python!")Answer: Hello, Python!
Why: The string is printed exactly as written.
What is the output?
print("Latte", 4.5)Answer: Latte 4.5
Why: print inserts a space between the string and the number.
What does this code print?
name = "Maya"
print(f"Hi, {name}")Answer: Hi, Maya
Why: The f-string inserts Maya into the message.
What does the program output?
print("A", "B", sep="-")Answer: A-B
Why: sep replaces the default space with a hyphen.
Try the questions first
Open the practice page for Python Print and Strings and answer the same 12 questions with instant feedback.