Skip to content

Commit 79169d1

Browse files
davepeckencukou
andauthored
Update Doc/library/string.templatelib.rst
Co-authored-by: Petr Viktorin <[email protected]>
1 parent 3827427 commit 79169d1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Doc/library/string.templatelib.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,25 @@ reassigned.
5959
>>> template = t"Hello {name}!"
6060
>>> type(template)
6161
<class 'string.templatelib.Template'>
62+
63+
Templates ars stored as sequences of literal :attr:`~Template.strings`
64+
and dynamic :attr:`~Template.interpolations`.
65+
A :attr:`~Template.values` attribute holds the interpolation values:
66+
6267
>>> template.strings
6368
('Hello ', '!')
69+
>>> template.interpolations
70+
(Interpolation('World', ...),)
6471
>>> template.values
6572
('World',)
6673

74+
The :attr:`!strings` tuple has one more element than :attr:`!interpolations`
75+
and :attr:`!values`; the interpolations “belong” between the strings.
76+
This may be easier to understand when tuples are aligned::
77+
78+
template.strings: ('Hello ', '!')
79+
template.values: ( 'World', )
80+
6781
While literal syntax is the most common way to create :class:`!Template`
6882
instances, it is also possible to create them directly using the constructor:
6983

0 commit comments

Comments
 (0)