Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8725d36

Browse files
miss-islingtonTommyUnrealhugovk
authored
[3.11] gh-107017: Change Chapter Strings to Texts in the Introduction chapter. (GH-107104) (#107168)
Co-authored-by: TommyUnreal <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 604eb04 commit 8725d36

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Doc/tutorial/introduction.rst

+20-20
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,25 @@ and uses the ``j`` or ``J`` suffix to indicate the imaginary part
138138

139139
.. _tut-strings:
140140

141-
Strings
142-
-------
141+
Text
142+
----
143143

144-
Besides numbers, Python can also manipulate strings, which can be expressed
145-
in several ways. They can be enclosed in single quotes (``'...'``) or
146-
double quotes (``"..."``) with the same result [#]_. ``\`` can be used
147-
to escape quotes::
144+
Python can manipulate text (represented by type :class:`str`, so-called
145+
"strings") as well as numbers. This includes characters "``!``", words
146+
"``rabbit``", names "``Paris``", sentences "``Got your back.``", etc.
147+
"``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double
148+
quotes (``"..."``) with the same result [#]_.
148149

149150
>>> 'spam eggs' # single quotes
150151
'spam eggs'
152+
>>> "Paris rabbit got your back :)! Yay!" # double quotes
153+
'Paris rabbit got your back :)! Yay!'
154+
>>> '1975' # digits and numerals enclosed in quotes are also strings
155+
'1975'
156+
157+
To quote a quote, we need to "escape" it, by preceding it with ``\``.
158+
Alternatively, we can use the other type of quotation marks::
159+
151160
>>> 'doesn\'t' # use \' to escape the single quote...
152161
"doesn't"
153162
>>> "doesn't" # ...or use double quotes instead
@@ -159,23 +168,14 @@ to escape quotes::
159168
>>> '"Isn\'t," they said.'
160169
'"Isn\'t," they said.'
161170

162-
In the interactive interpreter, the output string is enclosed in quotes and
163-
special characters are escaped with backslashes. While this might sometimes
164-
look different from the input (the enclosing quotes could change), the two
165-
strings are equivalent. The string is enclosed in double quotes if
166-
the string contains a single quote and no double quotes, otherwise it is
167-
enclosed in single quotes. The :func:`print` function produces a more
168-
readable output, by omitting the enclosing quotes and by printing escaped
169-
and special characters::
171+
In the Python shell, the string definition and output string can look
172+
different. The :func:`print` function produces a more readable output, by
173+
omitting the enclosing quotes and by printing escaped and special characters::
170174

171-
>>> '"Isn\'t," they said.'
172-
'"Isn\'t," they said.'
173-
>>> print('"Isn\'t," they said.')
174-
"Isn't," they said.
175175
>>> s = 'First line.\nSecond line.' # \n means newline
176-
>>> s # without print(), \n is included in the output
176+
>>> s # without print(), special characters are included in the string
177177
'First line.\nSecond line.'
178-
>>> print(s) # with print(), \n produces a new line
178+
>>> print(s) # with print(), special characters are interpreted, so \n produces new line
179179
First line.
180180
Second line.
181181

0 commit comments

Comments
 (0)