装饰器传参

# 计算你跟你对象的钱


def sum(money1, money2):
    print(money1 + money2)


sum(150,120)
sum(180,150)
# 换算汇率
def count_rate(money, money2,rate):
    print((money + money2)*rate)


count_rate(150,120,0.7)
count_rate(180,150,0.7)


count_rate(150,120,100)
count_rate(180,150,100)


print("*" * 90)


def count_rate(rate): # 为了保留汇率
    def sum(money,money2):
        print((money + money2)* rate)


    return sum
sum_usa = count_rate(0.7)
sum_usa(150,120)


sum_jpn = count_rate(100)
sum_jpn(150,120)


sum_usa(1000,2000) # 不用继续修改汇率,只用传部分参数

猜你喜欢

转载自blog.csdn.net/weixin_42139375/article/details/80555442
0条评论
添加一条新回复