Below is a simple example.
x is 1
Below is another example in which we import the names and grades of the students from the list and print them using the template.
Hi Ram, you`re 90 ratings Hi Ankit, you have 78 ratings Hello Bob, you have 92 ratings
The substitute () method raises a KeyError when a placeholder is not specified in a dictionary or keyword argument. For mail merge-style applications, user supplied data may not be complete and safe_substitute () may be more appropriate — it will leave placeholders unchanged if no data is available:
Another template application separates the program logic from the details of multiple output formats. This allows you to replace custom templates for XML files, text reports, and HTML web reports.
It should be noted that there are other ways to print formatted output as well, like% D for an integer,% F for a float, and etc. (see this for details)
This article is contributed by Siddharth Lalwani. If you like Python.Engineering and would like to contribute, you can also write an article and mail it to [email protected] See your article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you`d like to share more information on the topic under discussion