您当前的位置: 首页 >  Python

壹小俊

暂无认证

  • 1浏览

    0关注

    885博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

第九课--python模块与包

壹小俊 发布时间:2019-07-22 09:11:14 ,浏览量:1

模块类似于其他语言的引入。包是一个文件下有个__init__.py文件称为包。

类似与图片这个样子。hellos文件是一个包。

看案例。

hello.py

def hello():
    return 'hellos'

16_包.py

from hellos import hello

a = hello.hello()
print(a)

上面是包的使用。包的使用也是引入,但是他是一个文件夹下的文件。

接下来看模块的使用。模块在python中使用的频率很多,如os,math等等。

但是自定义的模块就是一个文件,这个文件不能和python内置的模块名称重合。

如下使用:

support.py(这是模块)

def print_func():
    return 'Hello'

16_模块.py(使用模块)

import support

a = support.print_func()
print(a)

 

关注
打赏
1664335782
查看更多评论
立即登录/注册

微信扫码登录

0.0495s