Created
February 25, 2020 20:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> # 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