Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Created February 25, 2020 20:54
Show Gist options
  • Save luisenriquecorona/0c58bc72cc2f1e1f8109133a996b3d8e to your computer and use it in GitHub Desktop.
Save luisenriquecorona/0c58bc72cc2f1e1f8109133a996b3d8e to your computer and use it in GitHub Desktop.
As a more advanced extension, string formatting also allows conversion targets on the left to refer to the keys in a dictionary coded on the right and fetch the corresponding values.
>>> # Template with substitution targets
>>> reply = """
Greetings...
Hello %(name)s!
Your age is %(age)s
"""
>>> values = {'name': 'Bob', 'age': 40} # Build up values to substitute
>>> print(reply % values) # Perform substitutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment