函数对象+函数嵌套+名称空间与作用域+闭包函数

# 函数对象
# 一切皆对象
# 函数是第一类对象,指的是函数的内存地址可以像变量一样去使用(函数可以被当做数据处理)
# x=10
#
def func(): #func = <function func at 0x0000028E571689D8>
print('from func')
# print(func)

x='hello'
# 1,引用
# y=x
# f=func
# print(f)
# f()

# 2,当做参数传给另个函数

# def foo(func):
# print(func)
# func()
# foo(func)

# 3,可以当做函数的返回值
# def foo(x):
# return x
# res = foo(func)
# print(res)
# res()

# 4,可以当做个容器类型的元素
# l = [x,]
# l = [func,]


# 函数对象的应用
# def register():
# print('正在注册')
#
# def login():
# print('正在登陆')
#
# def shopping():
# print('正在购物')
#
# def pay():
# print('正在支付')
#
# def transfer():
# print('正在转账')
#
# func_dic = {
# '1':register,
# '2':login,
# '3':shopping,
# '4':pay,
# '5':transfer
# }
#
# while True:
# msg = ("""
# 0 退出
# 1 注册
# 2 登录
# 3 购物
# 4 支付
# 5 转账
# """
# )
# print(msg)
# choice = input('请输入要操作的指令>>: ').strip()
# if choice == '0':break
# if choice not in func_dic:
# print('输入的有误')
# continue
# func_dic[choice]()

猜你喜欢

转载自www.cnblogs.com/zhangrenguo/p/9707925.html