当前位置:网站首页>Put functions in modules

Put functions in modules

2022-07-05 13:01:00 South Lake Fishing Song

 Insert picture description here
 Insert picture description here

# ------------- compute.py ---------------------------

def add(x,y):
    return x + y

def sub(x,y):
    return x - y

def mul(x,y):
    return x * y

def div(x,y):
    return x / y

# ------------- main.py ---------------------------

import compute as cp
print(cp.add(3,5))
print(cp.sub(3,5))
print(cp.mul(3,5))
print(cp.div(3,5))

from compute import add,sub,mul,div
print(add(3,5))
print(sub(3,5))
print(mul(3,5))
print(div(3,5))

from compute import * #  Not recommended 
print(add(3,5))
print(sub(3,5))
print(mul(3,5))
print(div(3,5))


原网站

版权声明
本文为[South Lake Fishing Song]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051240052525.html