f-string Debug Specifier And Conversions

The = specifier prints each expression beside its repr for self-documenting debug output, and the !r !s !a conversions pick the shape before formatting.

PythonData Integrity

Code

pythonsnippet
15 lines
ratio = 0.85
name = "café"
count = 3

# {expr=} is self-documenting debugging: expression text, equals sign, and repr in one print
print(f"{ratio=}")
print(f"{count * 2=}")
print(f"{list(range(3))=}")

# the !r/!s/!a conversions choose the pre-formatting shape: repr keeps quotes, ascii escapes non-ASCII
print(f"repr: {name!r} | str: {name!s} | ascii: {name!a}")

# the = specifier composes with format specs: equals sign first, precision after
print(f"{ratio=:.2f}")
print(f"{count=:03d}")

Inside the snippet

Module-level bindings hold the data — ratio, name, count — with no function scope in between.

Where you would put it to use

The demo output is labeled (repr:), so every printed line maps back to its originating operation.

Interactive Tools for This Topic

FAQ

Is a package install part of the setup?
No. Installation is unnecessary because only built-in APIs are used. Its state lives in module-level bindings: `ratio`, `name`, `count`.