def test1(func): def test2(root,key): if root == "root" and key ==123: print("您的用户名和密码输入正确") else: print("您的用户名或密码输入错误") return test2 @test1 def test3(root,key): pass test3("root",1234)
输出>>>您的用户名或密码输入错误
本文通过一个Python装饰器的示例代码展示了如何验证用户名和密码的正确性,并讨论了当参数不符合预期时的错误处理方式。该示例有助于理解装饰器的基本用法及其在实际应用中的作用。
def test1(func): def test2(root,key): if root == "root" and key ==123: print("您的用户名和密码输入正确") else: print("您的用户名或密码输入错误") return test2 @test1 def test3(root,key): pass test3("root",1234)
输出>>>您的用户名或密码输入错误
219

被折叠的 条评论
为什么被折叠?