01.02

Strings, f-strings, and t-strings

skillmaxingPython with AIStrings, f-strings, and t-strings
Visual lesson

Strings, f-strings, and t-strings

Included with Pro · 4:25
Lessons · 987 words

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.

Pro

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.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online