From 27bd6d5bacbd6d6b67808120586d78958a062ef6 Mon Sep 17 00:00:00 2001 From: Tomas Smolik Date: Sun, 23 Jul 2023 11:16:39 +0200 Subject: [PATCH 1/8] Change Strings to Texts in introduction chapter. While term "string" is well known in computer science, it might not resonate with beginners or non-technical individuals. Term Texts emphasize practical application in similar way to Numbers and Lists chapters. This can make the introduction part less intimidating and more beginner-oriented. On the other hand people comming from other technologies will not be surprised that text is represented with strings. --- Doc/tutorial/introduction.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index ebc2e9187534b4..954691260ea223 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -138,13 +138,14 @@ and uses the ``j`` or ``J`` suffix to indicate the imaginary part .. _tut-strings: -Strings +Texts ------- -Besides numbers, Python can also manipulate strings, which can be expressed -in several ways. They can be enclosed in single quotes (``'...'``) or -double quotes (``"..."``) with the same result [#]_. ``\`` can be used -to escape quotes:: +Different kinds of text have the type :class:`str`. This includes +characters "``!``", words "``rabbit``", names "``Paris``", sentences +"``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single +quotes (``'...'``) or double quotes (``"..."``) with the same result [#]_. +``\`` can be used to escape quotes:: >>> 'spam eggs' # single quotes 'spam eggs' From 3edff8bb78e280299b227e25d6f740d15a1401c1 Mon Sep 17 00:00:00 2001 From: Tomas Smolik Date: Sun, 23 Jul 2023 12:30:11 +0200 Subject: [PATCH 2/8] New structure of first paragraph in Text chapter. --- Doc/tutorial/introduction.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index 954691260ea223..f36cb7804cc41a 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -138,17 +138,24 @@ and uses the ``j`` or ``J`` suffix to indicate the imaginary part .. _tut-strings: -Texts +Text ------- -Different kinds of text have the type :class:`str`. This includes -characters "``!``", words "``rabbit``", names "``Paris``", sentences -"``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single -quotes (``'...'``) or double quotes (``"..."``) with the same result [#]_. -``\`` can be used to escape quotes:: +Python can manipulate text (represented by type :class:`str`, so called +"strings") as well as numbers. This includes characters "``!``", words +"``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. +"``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double +quotes (``"..."``) with the same result [#]_. >>> 'spam eggs' # single quotes 'spam eggs' + >>> "Paris rabbit got your back :)! Yay!" # double quotes + 'Paris rabbit got your back :)! Yay!' + >>> '1975' # digits and numerals enclosed in quotes are also strings + '1975' + +To quote a quote, we need to "escape" it, by preceding it with ``\``:: + >>> 'doesn\'t' # use \' to escape the single quote... "doesn't" >>> "doesn't" # ...or use double quotes instead From de2e3c5da5a06b6eec3eb3f4e777d3bfebd7e218 Mon Sep 17 00:00:00 2001 From: Tomas Smolik Date: Sun, 23 Jul 2023 13:50:34 +0200 Subject: [PATCH 3/8] Refactor string quotes handling and examples. Changed the description, removed duplicate explanations and reworked examples so they are more consice with its paragraph. --- Doc/tutorial/introduction.rst | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index f36cb7804cc41a..77a06bb82f7af9 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -145,7 +145,7 @@ Python can manipulate text (represented by type :class:`str`, so called "strings") as well as numbers. This includes characters "``!``", words "``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double -quotes (``"..."``) with the same result [#]_. +quotes (``"..."``) with the same result [#]_. >>> 'spam eggs' # single quotes 'spam eggs' @@ -154,7 +154,8 @@ quotes (``"..."``) with the same result [#]_. >>> '1975' # digits and numerals enclosed in quotes are also strings '1975' -To quote a quote, we need to "escape" it, by preceding it with ``\``:: +To quote a quote, we need to "escape" it, by preceding it with ``\``. +Alternatively, we can use the other type of quotation marks:: >>> 'doesn\'t' # use \' to escape the single quote... "doesn't" @@ -167,23 +168,15 @@ To quote a quote, we need to "escape" it, by preceding it with ``\``:: >>> '"Isn\'t," they said.' '"Isn\'t," they said.' -In the interactive interpreter, the output string is enclosed in quotes and -special characters are escaped with backslashes. While this might sometimes -look different from the input (the enclosing quotes could change), the two -strings are equivalent. The string is enclosed in double quotes if -the string contains a single quote and no double quotes, otherwise it is -enclosed in single quotes. The :func:`print` function produces a more +In the interactive interpreter, the string definition and output string +can look different. The :func:`print` function produces a more readable output, by omitting the enclosing quotes and by printing escaped and special characters:: - >>> '"Isn\'t," they said.' - '"Isn\'t," they said.' - >>> print('"Isn\'t," they said.') - "Isn't," they said. >>> s = 'First line.\nSecond line.' # \n means newline - >>> s # without print(), \n is included in the output + >>> s # without print(), special characters are included in the string 'First line.\nSecond line.' - >>> print(s) # with print(), \n produces a new line + >>> print(s) # with print(), special characters are interpreted, so \n produces new line First line. Second line. From 0306f45478638b588efd933c3d37a4e826db47e3 Mon Sep 17 00:00:00 2001 From: Tomas Smolik Date: Sun, 23 Jul 2023 14:00:05 +0200 Subject: [PATCH 4/8] Replaced interactive interpreter with Python shell --- Doc/tutorial/introduction.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index 77a06bb82f7af9..dcf21932ae8a89 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -168,10 +168,9 @@ Alternatively, we can use the other type of quotation marks:: >>> '"Isn\'t," they said.' '"Isn\'t," they said.' -In the interactive interpreter, the string definition and output string -can look different. The :func:`print` function produces a more -readable output, by omitting the enclosing quotes and by printing escaped -and special characters:: +In the Python shell, the string definition and output string can look +different. The :func:`print` function produces a more readable output, by +omitting the enclosing quotes and by printing escaped and special characters:: >>> s = 'First line.\nSecond line.' # \n means newline >>> s # without print(), special characters are included in the string From 7bd1f2a8fc0b98598d9745fabd176fc9f0ed2f90 Mon Sep 17 00:00:00 2001 From: TommyUnreal <45427816+TommyUnreal@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:10:01 +0200 Subject: [PATCH 5/8] Adjust length to match header Co-authored-by: Hugo van Kemenade --- Doc/tutorial/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index dcf21932ae8a89..b6dab6c2cfd87d 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -139,7 +139,7 @@ and uses the ``j`` or ``J`` suffix to indicate the imaginary part .. _tut-strings: Text -------- +---- Python can manipulate text (represented by type :class:`str`, so called "strings") as well as numbers. This includes characters "``!``", words From bd02929c0111109d486520e7271cb2309a594c13 Mon Sep 17 00:00:00 2001 From: TommyUnreal <45427816+TommyUnreal@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:10:56 +0200 Subject: [PATCH 6/8] Fix grammar. Co-authored-by: Hugo van Kemenade --- Doc/tutorial/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index b6dab6c2cfd87d..f0dd35294a060a 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -141,7 +141,7 @@ and uses the ``j`` or ``J`` suffix to indicate the imaginary part Text ---- -Python can manipulate text (represented by type :class:`str`, so called +Python can manipulate text (represented by type :class:`str`, so-called "strings") as well as numbers. This includes characters "``!``", words "``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double From ef4f321e18e3ae8fcbd3ce9d51e8730fb0e9c42e Mon Sep 17 00:00:00 2001 From: TommyUnreal <45427816+TommyUnreal@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:12:00 +0200 Subject: [PATCH 7/8] Add a space before the hash to follow PEP 8 Co-authored-by: Hugo van Kemenade --- Doc/tutorial/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index f0dd35294a060a..b2a5086aeabe16 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -151,7 +151,7 @@ quotes (``"..."``) with the same result [#]_. 'spam eggs' >>> "Paris rabbit got your back :)! Yay!" # double quotes 'Paris rabbit got your back :)! Yay!' - >>> '1975' # digits and numerals enclosed in quotes are also strings + >>> '1975' # digits and numerals enclosed in quotes are also strings '1975' To quote a quote, we need to "escape" it, by preceding it with ``\``. From b737cacce990a17a1b97e3ff0b9145dc9f7971ef Mon Sep 17 00:00:00 2001 From: TommyUnreal <45427816+TommyUnreal@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:12:56 +0200 Subject: [PATCH 8/8] Add a space before the hash to follow PEP 8 Co-authored-by: Hugo van Kemenade --- Doc/tutorial/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index b2a5086aeabe16..f19c37201e4dc1 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -149,7 +149,7 @@ quotes (``"..."``) with the same result [#]_. >>> 'spam eggs' # single quotes 'spam eggs' - >>> "Paris rabbit got your back :)! Yay!" # double quotes + >>> "Paris rabbit got your back :)! Yay!" # double quotes 'Paris rabbit got your back :)! Yay!' >>> '1975' # digits and numerals enclosed in quotes are also strings '1975' pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy