Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7634947

Browse files
bpo-31454: Include information about "import X as Y" in Modules tutorial (pythonGH-4041)
(cherry picked from commit fbee882) Co-authored-by: Mario Corchero <[email protected]>
1 parent 07c13ee commit 7634947

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Doc/tutorial/modules.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ Note that in general the practice of importing ``*`` from a module or package is
108108
frowned upon, since it often causes poorly readable code. However, it is okay to
109109
use it to save typing in interactive sessions.
110110

111+
If the module name is followed by :keyword:`as`, then the name
112+
following :keyword:`as` is bound directly to the imported module.
113+
114+
::
115+
116+
>>> import fibo as fib
117+
>>> fib.fib(500)
118+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
119+
120+
This is effectively importing the module in the same way that ``import fibo``
121+
will do, with the only difference of it being available as ``fib``.
122+
123+
It can also be used when utilising :keyword:`from` with similar effects::
124+
125+
>>> from fibo import fib as fibonacci
126+
>>> fibonacci(500)
127+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
128+
129+
111130
.. note::
112131

113132
For efficiency reasons, each module is only imported once per interpreter

0 commit comments

Comments
 (0)