#类中的闭包操作
def Human():
name = 'Wiz'
phoneNumber = '11012011933'
dick_size = '800cm'
def eat():
print('human can eat')
def sleep():
print('human can sleep')
def show():
print('i can show u my super 800cm dick')
#闭包用的封装函数
def inner_return():
return (eat,sleep,show,name,phoneNumber,dick_size)#注意!闭包时封装的时函数本身,若想执行被封装的函数,应使用函数()的形式来调用函数
return inner_return
hm = Human()
funcs = hm()#获取Human中闭包返回的函数和参数
eat = funcs[0]
eat()
sleep = funcs[1]
sleep()
show = funcs[2]
show()
name = funcs[3]
print(name)
phone_number = funcs[4]
print(phone_number)
dick_size = funcs[5]
print(dick_size)
友情提示:
Python学习交流、资源共享群:563626388 QQ