From d54f806d1850a7aeac1b08464c9038294cf0d2c8 Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 11:02:29 +0800 Subject: [PATCH 1/6] Create 2020-07-27-23-02-27.bpo-41394.BEos8A.rst --- .../next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst new file mode 100644 index 00000000000000..12b52bf33c7bdc --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.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 815fad9028f523768555718b86d1fe7a449081ac Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 15:58:47 +0800 Subject: [PATCH 2/6] Update appendix.rst --- Doc/tutorial/appendix.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Doc/tutorial/appendix.rst b/Doc/tutorial/appendix.rst index 241a812037469e..80f8585d30f0ee 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -31,6 +31,32 @@ Typing an interrupt while a command is executing raises the :exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` statement. +.. _tut-var: + +Special ``_`` variable +------------------------- + +There is a special variable ``_`` in interactive mode, which stores the result of the last +evaluated expression. If the last expression evaluated to ``None``, then the value of ``_`` +is not updated. + +For example: + + >>> _ # Not defined yet + Traceback (most recent call last): + File "", line 1, in + _ + NameError: name '_' is not defined + >>> 1 + 2 + 3 + >>> _ + 3 + >>> print("1+2=3") + 1+2=3 + >>> _ # Doesn't store None returned by print() + 3 + >>> _+4 + 7 .. _tut-scripts: From 5c716e156f61d794dcadee7d6cf019f588e444fa Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 17:00:06 +0800 Subject: [PATCH 3/6] Added space around "+" --- 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 80f8585d30f0ee..72fd61d2ccea17 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -55,7 +55,7 @@ For example: 1+2=3 >>> _ # Doesn't store None returned by print() 3 - >>> _+4 + >>> _ + 4 7 .. _tut-scripts: From 49f1dfa20caf1df120ea34d0ba8c645207ed38dd Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 19:45:37 +0800 Subject: [PATCH 4/6] Remove trailing whitespace on line 39 --- 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 72fd61d2ccea17..ce35ef2a22ed1b 100644 --- a/Doc/tutorial/appendix.rst +++ b/Doc/tutorial/appendix.rst @@ -36,7 +36,7 @@ statement. Special ``_`` variable ------------------------- -There is a special variable ``_`` in interactive mode, which stores the result of the last +There is a special variable ``_`` in interactive mode, which stores the result of the last evaluated expression. If the last expression evaluated to ``None``, then the value of ``_`` is not updated. From 8d194a8becdda70504c4be10e8edbec7e5259c3b Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 19:47:39 +0800 Subject: [PATCH 5/6] Update 2020-07-27-23-02-27.bpo-41394.BEos8A.rst --- .../Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst index 12b52bf33c7bdc..6f735e8277c8c6 100644 --- a/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst @@ -1,2 +1,3 @@ -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 define of ``_`` and an example. From d5a85d59c736c2f0ba85e245a8df1b7a9ad1c9df Mon Sep 17 00:00:00 2001 From: wyz23x2 <52805709+wyz23x2@users.noreply.github.com> Date: Tue, 28 Jul 2020 20:11:29 +0800 Subject: [PATCH 6/6] Update 2020-07-27-23-02-27.bpo-41394.BEos8A.rst --- .../next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst index 6f735e8277c8c6..1da80580bf4de4 100644 --- a/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-23-02-27.bpo-41394.BEos8A.rst @@ -1,3 +1,3 @@ -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 define of ``_`` and an example.