python t-string

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2025 Jun 9 11:6
Editor
Edited
Edited
2025 Jun 9 11:10
Refs
Refs
Like f-strings, you can put expressions inside {}, but instead of evaluating to a string immediately, it creates a string.templatelib.Template object
from string.templatelib import Template name = "Alice" tpl = t"Hello, {name}!" print(tpl.strings, tpl.values) # -> ("Hello, ", "!"), ("Alice",)
This Template object provides the original string fragments and variable values separately through the .strings and .values properties, allowing developers to safely escape or post-process them as needed.
 
 
 
 
davepeck.org
Dave Peck's home on the web. Dave is an independent software developer, investor, and civic technologist.
 

Recommendations