#!/usr/bin/env python #coding=utf-8 from fun import add print "import add function from module fun" print add(1,5)
from rectangle import Rectangle from triangle import Triangle import fun rectangle = Rectangle() rectangle.set_value(3, 4) rectangle.set_color('blue') print(rectangle.area()) print(rectangle.get_color()) triangle = Triangle() triangle.set_value(3, 4) triangle.set_color("yellow") print(triangle.area()) print(triangle.get_color()) print(fun.add(4, 7))
#!/usr/bin/python3 # -*- coding: UTF-8 -*- '''一个.py文件就是一个模块,遇到 import 语句,如果模块在当前的搜索路径就会被导入''' import fun '''每个模块都有一个__name__属性,当其值是'__main__'时,表明该模块自身在运行,否则是被引入''' print(fun.__name__) print('模块内所有定义的名称:', dir(fun)) print(fun.add(2, 2)) '''只导入模块的指定部分,可以直接使用''' from fun import add print(add(3, 3))
#!/usr/bin/env python3 import sys import fun print("awesome") print("more awesome") print(sys.argv[0]) print(fun.add(2, 3)) print("good enough")
#!/usr/bin/env python #coding=utf-8 from fun import add print "import add function from module fun" print add(1, 5)
import fun#IMPORT THE FILE fun TO PERFORM ADDITION print(fun.add(10,20))
def test_add(self): result = fun.add(1, 2) self.assertEqual(result, 4)
import fun print("\"import\" fun") print(fun.add(1, 2)) print(fun.sub(1, 2)) print(fun.mul(1, 2)) print(fun.div(1, 2))
import fun as funct print(funct.add(9, 10))