13.2 C
Paris
Sunday, May 11, 2025

The very best new options and fixes in Python 3.14



A template string, or t-string, enables you to mix the template with a perform that operates on the template’s construction, not simply its output. You possibly can write a template handler that permits all variables positioned within the template, or solely variables of a selected kind, or solely variables that match some output, to be manipulated at output time. You possibly can additionally deal with the variables and the interpolating textual content as separate, otherwise typed objects.

As an illustration, if in case you have the template t"My title is {user_name}, and I am from {user_locale}", you could possibly have the variables user_name and user_locale mechanically cleaned of any HTML earlier than show. You possibly can additionally carry out transformations on the My title is and and I am from parts of the output mechanically, as these could be tagged with the particular kind Interpolation.

Template strings will make it far simpler to jot down template engines, e.g., Jinja2, or to duplicate a lot of the performance of these template engines instantly in Python with out the overhead of third-party libraries.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

error: Content is protected !!