Python入门 模块

module 模块

atestmodule.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'a test module'

def addFunc(a,b):
	return a+b

if __name__ == '__main__':
	print('atestmodule计算结果:',addFunc(1,1))

anothertestmodule.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

' a test module '

import atestmodule

print('调用anothermodule模块执行的结果是:',atestmodule.addFunc(12,23))

__name__ == 'main'的作用是为了使得Make a script both importable and executable,也就是说可以让模块既可以导入到别的模块中用,另外该模块自己也可执行。

参考文章

python使用模块

posted @ 2019-04-08 15:33  Draymonder  阅读(149)  评论(0编辑  收藏  举报