python : 'import module' vs 'import module as'

标签 python syntax import module

下面两种说法有区别吗?

import os
import os as os

如果是这样,哪个更受欢迎?

最佳答案

它只是用来简化,比如

import random
print random.randint(1,100)

等同于:

import random as r
print r.randint(1,100)

所以你每次都可以使用r而不是random

关于 python : 'import module' vs 'import module as' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31469611/

相关文章:

objective-c - 在 Objective-C 接口(interface)中 #import 是否总是不合适?

r - 导入地址文本文件

Python Pandas 错误栏未绘制以及如何自定义索引

python - Keras网络训练速度下降

ios - 尝试注册 UICollectionViewCell 子类,但不断收到 "Cannot invoke ' registerClass' ......”

java - 为什么我不能在类之外的方法中使用数组?

python - 使用 Dropwhile 从嵌套循环快进 xrange?

python:无法连接 'str' 和 'tuple' 对象(应该可以!)

javascript - Javascript 如何知道作为函数参数传递的变量是 "event"

python - 使用相对导入动态导入模块的正确方法?