为什么我们需要在python中使用“ as”来导入

时间:2018-10-19 02:02:46

标签: python python-import

来自python文档:

 import_stmt:    "import" module ["as" name] ("," module ["as" name] )* 
          | "from" module "import" identifier ["as" name]
            ("," identifier ["as" name] )*
          | "from" module "import" "*" 
 module:         (identifier ".")* identifier

为什么我们需要为库定义别名?

1 个答案:

答案 0 :(得分:5)

有几次。

为避免名称冲突

Out[16]: 
              extracted                                        text
0  the dog eats the cat  the cat eats the dog. the dog eats the cat

避免长名

from bisect import bisect
from homework import bisect as my_bisect
# TODO: test if the two functions works similarly

做模因

import tensorflow as tf