1,函数定义和使用:
def substract(sub_a,sub_b):
sub_res =sub_a - sub_b
return sub_res
sub_test = substract(10,20)
print(“sub_test=”, sub_test)
def multply(mul_a,mul_b):
mul_res = mul_a * mul_b
return mul_res
mul_test = multply(2,4)
print(“mul_test=”,mul_test)
def add(add_a,add_b):
add_res = add_a + add_b
return add_res
add_test = add(10,40)
print (“add_test=”,add_test)
def devide(dev_a,dev_b):
try:
div_res = dev_a / dev_b
except Exception :
print(“An exception happend :”)
return div_res
div_test = devide(10,10)
print(“dev_test=”,div_test)
2,运行结果: