In Python, a template string can be created using the str.format()
method or by using f-strings (formatted string literals). Here is an example of how to create a template string using f-strings:
main.py96 chars5 lines
Output:
main.py38 chars2 lines
Alternatively, you can use the str.format()
method to create a template string:
main.py106 chars5 lines
Output:
main.py38 chars2 lines
In both cases, the curly braces {}
are used as placeholders for the variables name
and age
. You can add more placeholders to the template string as needed, and pass in more variables to format()
or use more f-strings.
gistlibby LogSnag