summaryrefslogtreecommitdiff
path: root/Doc/tutorial/modules.rst
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-02-25 11:35:52 -0800
committerGitHub <noreply@github.com>2018-02-25 11:35:52 -0800
commite48e6499bbad56f7cc665efa25ae4847f51dbc38 (patch)
tree26c59a379b87d622138e106b1335c3d28c7a6f12 /Doc/tutorial/modules.rst
parentddf2485103c1e56ba4f290641247dfa07fcbe7f3 (diff)
downloadcpython-git-e48e6499bbad56f7cc665efa25ae4847f51dbc38.tar.gz
bpo-31454: Include information about "import X as Y" in Modules tutorial (GH-4041)
(cherry picked from commit fbee88244e8921afdb29fde51a9a010a8ae18277) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
Diffstat (limited to 'Doc/tutorial/modules.rst')
-rw-r--r--Doc/tutorial/modules.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst
index 2be03ac6ae..584d4fd72e 100644
--- a/Doc/tutorial/modules.rst
+++ b/Doc/tutorial/modules.rst
@@ -112,6 +112,25 @@ Note that in general the practice of importing ``*`` from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
use it to save typing in interactive sessions.
+If the module name is followed by :keyword:`as`, then the name
+following :keyword:`as` is bound directly to the imported module.
+
+::
+
+ >>> import fibo as fib
+ >>> fib.fib(500)
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
+
+This is effectively importing the module in the same way that ``import fibo``
+will do, with the only difference of it being available as ``fib``.
+
+It can also be used when utilising :keyword:`from` with similar effects::
+
+ >>> from fibo import fib as fibonacci
+ >>> fibonacci(500)
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
+
+
.. note::
For efficiency reasons, each module is only imported once per interpreter