标签:
start
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv
print("passed user verification...")
return func #返回func,即是tv的内存地址
def tv():
print("welcome [%s] to home page")
tv = login(tv) #tv是变量
tv() #tv加上括号,就调用tv函数
结果:
passed user verification...
welcome [%s] to home page
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv
print("passed user verification...")
return func #返回func,即是tv的内存地址
@login #tv=login(tv)
def tv(name):
print("welcome [%s] to home page" %name)
tv("yaobin") #tv加上括号,就调用tv函数
结果:
passed user verification...
welcome [yaobin] to home page
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv
print("passed user verification...")
return func #返回func,即是tv的内存地址
@login #tv=login(tv)
def tv(name):
print("welcome [%s] to home page" %name)
结果:
passed user verification...
#我都还没有tv("yaobin"),就已经执行了验证
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv
def inner(arg):
print("passed user verification...")
#return func #这里不用return了,应该是执行!
func(arg) #tv
return inner #login 返回inner的内存地址
@login #tv=login(tv)
def tv(name):
print("welcome [%s] to home page" %name)
#tv("yaobin") #这里加上括号,相当于调用inner!而且有参数,所有inner也要有参数,func也要有参数
①结果:
空
②把#tv("yaobin")打开,结果:
passed user verification...
welcome [yaobin] to home page
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv or moive
def inner(arg1,arg2):
print("passed user verification...")
#return func #这里不用return了,应该是执行!
func(arg1,arg2) #tv or moive
return inner #login 返回inner的内存地址
@login
def moive(name,anything): #moive=moive(tv)
print("welcome [%s] to home page" %name)
@login #tv=login(tv)
def tv(name,passwd):
print("welcome [%s] to home page" %name)
print("my passwd is :[%s] " %passwd)
tv("yaobin","123456")
print("")
moive("hy","anything")
#结果
passed user verification...
welcome [yaobin] to home page
my passwd is :[123456]
passed user verification...
welcome [hy] to home page
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv
def inner(*args,**kwargs):
print("passed user verification...")
#return func #这里不用return了,应该是执行!
func(*args,**kwargs) #tv or moive
return inner #login 返回inner的内存地址
@login #moive=moive(tv)
def moive(name,passwd=123456): #passwd有默认参数
print("welcome [%s] to home page" %name)
print("my passwd is :[%s] " %passwd)
@login #tv=login(tv)
def tv(name,passwd=456789): #passwd有默认参数
print("welcome [%s] to home page" %name)
print("my passwd is :[%s] " %passwd)
#①自定义参数
moive("hy","one")
tv("yaobin","two")
print("")
#②使用默认参数
moive("hy")
tv("yaobin")
结果:
passed user verification...
welcome [hy] to home page
my passwd is :[one]
passed user verification...
welcome [yaobin] to home page
my passwd is :[two]
passed user verification...
welcome [hy] to home page
my passwd is :[123456]
passed user verification...
welcome [yaobin] to home page
my passwd is :[456789]
#!/usr/bin/python
#coding=utf-8
#py3
def login(func): #func=tv or moive
def inner(*args,**kwargs):
print("passed user verification...")
#return func #这里不用return了,应该是执行!
return func(*args,**kwargs) #tv or moive ##这里要return,不然没有返回值
return inner #login 返回inner的内存地址
@login #moive=moive(tv)
def moive(name,passwd=123456): #passwd有默认参数
print("welcome [%s] to home page" %name)
print("my passwd is :[%s] " %passwd)
@login #tv=login(tv)
def tv(name,passwd=456789): #passwd有默认参数
print("welcome [%s] to home page" %name)
print("my passwd is :[%s] " %passwd)
return name,passwd
moive("hy") #moive()加上括号,相当于调用inner!而且有参数,所有inner也要有参数,func也要有参数
print("")
t= tv("yaobin","my passwd haha") #tv()加上括号,相当于调用inner!而且有参数,所有inner也要有参数,func也要有参数
print(t) #看返回值
结果:
passed user verification...
welcome [hy] to home page
my passwd is :[123456]
passed user verification...
welcome [yaobin] to home page
my passwd is :[my passwd haha]
(‘yaobin‘, ‘my passwd haha‘)
标签:
原文地址:http://www.cnblogs.com/binhy0428/p/5170956.html