ernest.howe
ernest.howe Jul 19, 2026 • 20 views

Multiple Choice Questions on String Formatting in Python

Hey everyone! 👋 Let's test your knowledge of Python string formatting! This quiz will help you practice and solidify your understanding. Good luck! 🍀
💻 Computer Science & Technology
🪄

🚀 Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

✅ Best Answer
User Avatar
robert.jackson Dec 28, 2025

📚 Quick Study Guide

  • String Formatting Overview: String formatting allows you to insert variables or values into a string.
  • 🔑 `%` Operator (Old Style): Uses format specifiers like `%s` (string), `%d` (integer), `%f` (float). Example: `'Hello, %s' % 'World'`.
  • 💎 `.format()` Method (New Style): Uses replacement fields denoted by curly braces `{}`. Example: `'Hello, {}'.format('World')`. You can also use named placeholders: `'Hello, {name}'.format(name='World')`.
  • 🌟 f-strings (Python 3.6+): Prefix the string with `f` and embed expressions inside curly braces. Example: `name = 'World'; f'Hello, {name}'`. f-strings are generally the most readable and efficient.
  • 🔢 Format Specifiers: Within replacement fields (e.g., in `.format()` or f-strings), you can use format specifiers for precise control over output (e.g., `:.2f` for two decimal places).

Practice Quiz

  1. Which of the following is the oldest method for string formatting in Python?
    1. A) f-strings
    2. B) `.format()` method
    3. C) `%` operator
    4. D) Template strings
  2. What is the correct syntax for using f-strings?
    1. A) `string.f'Hello, {name}'`
    2. B) `f'Hello, {name}'`
    3. C) `'Hello, {name}'.f`
    4. D) `'Hello, ' + {name}`
  3. Which method is generally considered the most readable and efficient?
    1. A) `%` operator
    2. B) `.format()` method
    3. C) f-strings
    4. D) Template strings
  4. How would you format a float variable `num` to display only two decimal places using the `.format()` method?
    1. A) `'{:.2}'.format(num)`
    2. B) `'{.2f}'.format(num)`
    3. C) `'{:2f}'.format(num)`
    4. D) `'{: .2f}'.format(num)`
  5. Which of the following is a valid way to use named placeholders with the `.format()` method?
    1. A) `'Hello, {name}'.format('World')`
    2. B) `'Hello, {}'.format(name='World')`
    3. C) `'Hello, {name}'.format(name='World')`
    4. D) `'Hello, {name=World}'.format()`
  6. What will be the output of the following code: `print('The value is %d' % 3.14)`?
    1. A) The value is 3.14
    2. B) The value is 3
    3. C) Error
    4. D) The value is 3.0
  7. Which string formatting technique is ONLY available in Python 3.6 and later?
    1. A) `%` operator
    2. B) `.format()` method
    3. C) f-strings
    4. D) Template strings
Click to see Answers
  1. C
  2. B
  3. C
  4. B
  5. C
  6. B
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀