Answer key · 12 questions

Python Print and Strings Exercises With Answers

All 12 questions for Python Print and Strings in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

Which call prints two values separated by a space?

  1. print("Latte" + 4.5)
  2. print("Latte" 4.5)
  3. print("Latte", 4.5)correct
  4. print("Latte"; 4.5)

Answer: print("Latte", 4.5)

Why: print() accepts multiple arguments and puts a space between them by default.

02 · Multiple choice

Which string correctly inserts the value of name into the message?

  1. "Hello, name"
  2. f"Hello, {name}"correct
  3. f"Hello, name"
  4. "Hello, {name}"

Answer: f"Hello, {name}"

Why: An f-string uses curly braces to evaluate the variable inside the text.

03 · Multiple choice

What does print("A", "B", sep="-") display?

  1. A B
  2. AB
  3. A-Bcorrect
  4. A"-"B

Answer: A-B

Why: sep replaces the default space between the two values.

04 · Multiple choice

Which literal creates a string that can span multiple lines?

  1. A string in single quotes on one line
  2. A string starting with f
  3. A string in double quotes on one line
  4. A triple-quoted stringcorrect

Answer: A triple-quoted string

Why: Triple quotes allow a string literal to include line breaks.

05 · Fill in the blank

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.

06 · Fill in the blank

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.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

What is printed?

print("Hello, Python!")

Answer: Hello, Python!

Why: The string is printed exactly as written.

10 · Predict output

What is the output?

print("Latte", 4.5)

Answer: Latte 4.5

Why: print inserts a space between the string and the number.

11 · Predict output

What does this code print?

name = "Maya"
print(f"Hi, {name}")

Answer: Hi, Maya

Why: The f-string inserts Maya into the message.

12 · Predict output

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.

Practice this lesson