Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7634947

Browse files
bpo-31454: Include information about "import X as Y" in Modules tutorial (pythonGH-4041)
(cherry picked from commitfbee882)Co-authored-by: Mario Corchero <mariocj89@gmail.com>
1 parent07c13ee commit7634947

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)

[8]ページ先頭

©2009-2025 Movatter.jp