Strings, f-strings, and t-strings
Strings, f-strings, and t-strings
A Python string is an immutable sequence of Unicode characters. Every method on it returns a new string; nothing modifies one in place. Bytes are a separate type, and the boundary between the two, encode and decode, is exactly where HTTP bodies, files, and model responses cross into your program. Most of the string work in a backend is formatting: putting a ticket id, a customer name, and a model's answer into a message with the right shape. Python has had several ways to do that, and since 3.6 the answer is the f-string.
Python 3.14 adds a sibling, the t-string. It looks like an f-string with a t prefix, but instead of producing text it produces a Template object holding the literal parts and the interpolated values separately. That separation is the point. When the value is customer text going into a prompt, a SQL query, or an HTML page, you want to decide how it is escaped before it is joined, and an f-string has already joined it by the time you can look.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.