学习笔记(51):Python入门教程-函数进阶-装饰器

立即学习:https://edu.csdn.net/course/play/24459/296347?utm_source=blogtoedu

装饰器介绍

如果没有装饰器时:

account = {
    "is_authenticated":False,
    "username":"alex",
    "password":"abc123"
}
def login(func):
    if account["is_authenticated"] is False:
        username = input("user:")
        password = input("password")
        if username == account["username"] and password == account["password"]:
            print("welcome login")
            account["is_authenticated"] = True
            func()
        else:
            print("wrong username or password")
    else:
        print("already login")
        func()

def home():
    print("首页")
def america():
    #login()
    print("欧美")
def japan():
    print("日韩")
def henan():
    #login()
    print("河南")

home()
login(america)
login(henan)

 

你可能感兴趣的:(研发管理,python,编程语言,Python,小猿圈,Python入门教程)