Skip to content

Commit 7b660be

Browse files
committed
Start writing the t-strings part of lexical analysis
1 parent 1e47362 commit 7b660be

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Doc/reference/lexical_analysis.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,31 @@ See also :pep:`498` for the proposal that added formatted string literals,
913913
and :meth:`str.format`, which uses a related format string mechanism.
914914

915915

916+
.. _t-strings:
917+
.. _template-string-literals:
918+
919+
t-strings
920+
---------
921+
922+
.. versionadded:: 3.14
923+
924+
A :dfn:`template string literal` or :dfn:`t-string` is a string literal
925+
that is prefixed with ``'t'`` or ``'T'``. These strings follow the same
926+
syntax and evaluation rules as `formatted string literals <f-strings>`_, with
927+
the following differences:
928+
929+
- Rather than evaluating to a `str` object, t-strings evaluate to a
930+
`Template` object from the :mod:`string.templatelib` module.
931+
932+
- Evaluated expressions are *not* formatted using the
933+
:func:`format` protocol; :meth:`~object.__format__` is *not* invoked. Instead,
934+
the expressions are evaluated and a new `Interpolation` object (also from the
935+
:mod:`string.templatelib` module) is created, which contains the evaluated
936+
value of the expression. That `Interpolation` object is found in the containing
937+
`Template`.
938+
939+
940+
916941
.. _numbers:
917942

918943
Numeric literals

0 commit comments

Comments
 (0)