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

Skip to content

bpo-31454: Include information about "import X as Y" in tutorial #4041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Doc/tutorial/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down