import引用扩展模块和了解扩展模块

文章链接: https://blog.csdn.net/qq_40801709/article/details/86505486 

  • Import <模块>
    • 每次使用需  模块.函数
  • Import <模块> [as <别名>]
    • 将模块中的函数等名称导入到当前程序
    • 可以给导入的命名空间替换一个新的名字
  • From <模块> import <函数>
    • 引入模块中的某个函数
    • 调用时不需要加上命名空间
  • From <模块> import *
    • 调用时不需要加上命名空间
    • 但是不建议,多个模块使用这种写法会导致命名冲突
  • 查看扩展模块
    • Import time
    • dir(time)
    • Help (time.time)不需要加括号
  • Help(time.time)和help(time.time())的区别?
    • >>> help(time.time()) == help(float) >>>Help on float object:
    • >>> help(time.time) == 分析函数     >>>Help on built-in function time in module time

除此之外,还可以通过runoob.com具体查询部分模块。

具体实例:

>>> import time
>>> time.time()
1547611726.4722903
>>> import time as tm
>>> tm.time()
1547611739.3922358
>>> from time import time
>>> time()
1547611753.8672888
>>> from time import *
>>> time()
1547611767.1580853
>>> dir(time)
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']

>>> help(time)
Help on built-in function time in module time:

time(...)
    time() -> floating point number
    
    Return the current time in seconds since the Epoch.
    Fractions of a second may be present if the system clock provides them.

猜你喜欢

转载自blog.csdn.net/qq_40801709/article/details/86505486
今日推荐