zoukankan      html  css  js  c++  java
  • 函数对象

    函数是第一类对象:就是指函数名指向的值也可以被当做参数传递。

    1, 函数名可以被传递。

     name = "yangxin"

     x = name

     print (x)

     print ( id (x) )

    结果: yangxin

    地址; x 和name相同

    #上方的x 和name 同时在内存空间只想了yangxin 所以结果一样

    2,函数名 可以被当作参数传递给其他函数

    def func ():

      print("from func")

    def index (args):

      print  ("args")

      args ()

      print("from index")

     index(l)

     index(func)

    #3函数名可以被当作函数的返回值
    # def index():
    # print("index")
    #
    # def func():
    # print("func")
    # return index
    # res = func()
    # print(res)
    # res()
    #运行结果func
    # <function index at 0x0000023EFCBD1E18>
    # index
    #
    #4函数名可以被当作容器类型的参数
    # def func():
    # print("func")
    # print(func())
    # l = [1,2,func,func()]#这时候就等同于在这个列表里面存的是[1, 2, <function func at 0x00000187DA1F1E18>, None]
    # print(l)
    #


    #循环打印项目功能提示信息 供客户选择 用户选择谁就执行谁
    def register():
    username = input("username>>>:").strip()
    pwd = input("password>>>:").strip()
    print(username,pwd)
    print("register")
    #def login():
    # print("login")
    #def teansfer():
    # print("teansfer")
    #def shopping():
    # print("shopping")
    #def pay():
    # print("pay")
    #
    #msg = """
    # 1 注册
    # 2 登录
    # 3转账
    # 4购物
    # 5支付
    # """
    """func_dict = {
    '1':register,
    '2':login,
    '3':transfer,
    '4':shopping,
    '5':pay,
    }
    while True:
    print(msg)
    choice = input("请输入你要执行的功能>>>:").strip()
    if choice in func_dict:
    func_dict.get(choice)()
    else:
    print("您输入的功能暂时没有")
  • 相关阅读:
    Study Plan The Twelfth Day
    Study Plan The Fifteenth Day
    Study Plan The Seventeenth Day
    Study Plan The Tenth Day
    Study Plan The Eighth Day
    Study Plan The Eleventh Day
    Study Plan The Sixteenth Day
    Study Plan The Thirteenth Day
    Study Plan The Fourteenth Day
    Study Plan The Ninth Day
  • 原文地址:https://www.cnblogs.com/yangxinpython/p/11164297.html
Copyright © 2011-2022 走看看