]> granicus.if.org Git - python/commitdiff
bpo-31454: Include information about "import X as Y" in Modules tutorial (GH-4041)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 25 Feb 2018 19:38:24 +0000 (11:38 -0800)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2018 19:38:24 +0000 (11:38 -0800)
(cherry picked from commit fbee88244e8921afdb29fde51a9a010a8ae18277)

Co-authored-by: Mario Corchero <mariocj89@gmail.com>
Doc/tutorial/modules.rst

index 6fb4ffda2b84e0081760f39322118db3b073b7b8..ec3bd9c53d2ec6ce03bd49c2f2fb018267ba146f 100644 (file)
@@ -108,6 +108,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