Skip to content

1.3.3 Formatted Output with f-Strings

Formatted strings, or f-strings, provide a clear and readable way to embed variables and expressions inside strings.
They are the recommended method for string formatting in modern Python.


What Is an f-String?

An f-string:

  • Is prefixed with the letter f
  • Allows expressions inside {} braces
  • Is evaluated at runtime

This makes output more expressive and easier to read.


Advantages of f-Strings

  • Cleaner syntax compared to older formatting methods
  • Better readability
  • Supports expressions directly inside strings

Common Use Cases

  • Displaying variables in messages
  • Formatting numerical output
  • Creating clear and informative logs

📌 Note:
f-strings improve code readability and should be preferred over older string formatting styles.