第一类对象

# def fn():
#     print("我叫fn")

# fn()
# print(fn)  # <function fn at 0x0000000001D12E18>
# fn()
# gn = fn # 函数名可以进行赋值
# print(gn)
# gn()

# fn = 666
# print(fn) # 666


# def func1():
#     print("朱祁镇")
#
# def func2():
#     print("徐阶")
#
# def func3():
#     print("王阳明")
#
# def func4():
#     print("魏忠贤")
#
# lst = [func1, func2, func3, func4] # 函数+() 就是调用.
# print(lst)
#
# # lst[0]()
# # for el in lst: #  el是列表中的每一项.
# #     el() # 拿到函数. 执行函数
#
#
# a = 10
# b = 20
# c = 30
# lst = [a, b, c]
# print(lst)


# def wrapper():
#     def inner():
#         print("我的天, 还可以扎样写")
#     print(inner) # <function wrapper.<locals>.inner at 0x00000000028989D8>
#     inner()
#     return inner
#
# ret = wrapper() # <function wrapper.<locals>.inner at 0x00000000028989D8>
# print(ret)
# ret()

# def wrapper():
#     def inner():
#         print("哈哈哈")
#     return inner  # 函数名可以像返回值一样返回
#
# ret = wrapper()
# ret() # 在函数外面访问了函数内部的函数
# ret()
# ret()

#
# def func1():
#     a = 10
#     return a
# print(func1())

# 函数可以作为参数进行传递

def func1():
    print("谢晋")

def func2():
    print('杨士奇')

def func3():
    print('徐渭')

def func4():
    print("柳如是")

# 代理. 装饰器的雏形
def proxy(a): # a就是变量. 形参
    print("我是代理")
    a()
    print("代理执行完毕")

proxy(func1)
proxy(func3)
proxy(func4)

  

posted @ 2018-12-10 19:04  =-=-  阅读(161)  评论(0编辑  收藏  举报