From a8fc1afe82fb7dd66e569a076cdfe9ccd003d8a1 Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:35:30 +0800 Subject: [PATCH 1/7] Update appendix.rst --- Doc/tutorial/appendix.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst index 241a812037469e..d47f3d8f2cc862 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -31,6 +31,26 @@ Typing an interrupt while a command is executing raises the :exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` statement. +.. _special-var: + +Special ``_`` variable +------------------------- + +There is a special variable ``_`` in interactive mode. It stores the result of the +last evaluation (*except* ``None``), stored in the :mod:`builtins` module. + +For example: + + >>> 1 + 2 + 3 + >>> _ + 3 + >>> print("1+2=3") + 1+2=3 + >>> _ # Doesn't store None returned by print() + 3 + >>> _+4 + 7 .. _tut-scripts: From d86b9e09410826b5da862d504e2e41fe0d31d75c Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:45:00 +0800 Subject: [PATCH 2/7] Fixed hyper to match "tut" --- Doc/tutorial/appendix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst index d47f3d8f2cc862..6335911ec6085b 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -31,7 +31,7 @@ Typing an interrupt while a command is executing raises the :exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` statement. -.. _special-var: +.. _tut-var: Special ``_`` variable ------------------------- From 7a56efda8a338b376dc7f7c025f530230b4a7fea Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:51:58 +0800 Subject: [PATCH 3/7] Update appendix.rst Made the statement more clear. Added example stating _ is not defined at the start. --- Doc/tutorial/appendix.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst index 6335911ec6085b..0a597e4d4afa06 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -36,11 +36,17 @@ statement. Special ``_`` variable ------------------------- -There is a special variable ``_`` in interactive mode. It stores the result of the -last evaluation (*except* ``None``), stored in the :mod:`builtins` module. +There is a special variable ``_`` in interactive mode, stored in the :mod:`builtins` +module. It stores the result of the last evaluated expression (*except* ``None`` +-- it remains unchanged). For example: + >>> _ # Not defined yet + Traceback (most recent call last): + File "", line 1, in + _ + NameError: name '_' is not defined >>> 1 + 2 3 >>> _ From dd9f627f9922705dbb465a8fda5d291ccd9280b2 Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 11:05:05 +0800 Subject: [PATCH 4/7] Create 2020-07-27-23-05-02.bpo-41394.BEos8A.rst --- .../next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst new file mode 100644 index 00000000000000..12b52bf33c7bdc --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst @@ -0,0 +1,2 @@ +Added "Special ``_`` Variable`` section to the 16. Appendix part of Python tutorial. +It includes the define of ``_`` and an example. From 8b4d79e5c695e0381eeb62b3f917617b01f1d067 Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 11:06:14 +0800 Subject: [PATCH 5/7] bpo-41394: Document '_' in interpreter tutorial --- .../next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst index 12b52bf33c7bdc..713d3eb107abe2 100644 --- a/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst @@ -1,2 +1,2 @@ Added "Special ``_`` Variable`` section to the 16. Appendix part of Python tutorial. -It includes the define of ``_`` and an example. +It includes the definition of ``_`` and an example. From 81dab86834de5a2ab40f795c7a30abc9ec3c24a5 Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 11:06:39 +0800 Subject: [PATCH 6/7] Update 2020-07-27-23-05-02.bpo-41394.BEos8A.rst --- .../next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst index 713d3eb107abe2..8ccfca2d549c0f 100644 --- a/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-05-02.bpo-41394.BEos8A.rst @@ -1,2 +1,2 @@ -Added "Special ``_`` Variable`` section to the 16. Appendix part of Python tutorial. +Added "Special ``_`` Variable" section to the "16. Appendix" part of Python tutorial. It includes the definition of ``_`` and an example. From 2981333d6f263790c7b41d00673daa9faace1b1f Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 11:41:00 +0800 Subject: [PATCH 7/7] bpo-41394: State special _ in appendix of tutorial --- Doc/tutorial/appendix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst index 0a597e4d4afa06..6d74137960d86c 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -38,7 +38,7 @@ Special ``_`` variable There is a special variable ``_`` in interactive mode, stored in the :mod:`builtins` module. It stores the result of the last evaluated expression (*except* ``None`` --- it remains unchanged). +— it remains unchanged). For example: