zoukankan      html  css  js  c++  java
  • 内置函数,匿名函数

    一堆内置函数

    exec 没有返回值
    eval 有返回值
    compile 编译代码

    sorted(iterable, key=function排序规则, reverse=翻转)
    map(function, iterable)
    filter(function, iterable)

    匿名函数 :
    lambda 参数: 返回值
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    # eval 是把字符串类型的数据作为代码进行执行
    # s = "18+2"
    # ret = eval(s) # 执行字符串类型的代码
    # print(ret)
     
    # code = input("请输入你要执行的代码:")
    # ret = eval(code)
    # print(ret)
     
     
    # s = "{'name':'alex', 'age':18, 'isMan':False}" # 字符串
    # # 把字符串类型的代码还原回字典, 列表, 元组
    # ret = eval(s)  # 侧重的有返回值
    # print(ret)
    # print(type(ret))
     
     
    # exec execute 执行字符串类型的代码, 不能太长. 不能太乱
    # code = input("请输入你要执行的代码")
    # exec(code) # 没有返回值. 想要返回值用eval
    # print(a)   # pycharm报错不一定准
     
     
    # compile 编译: 把你要执行的代码先预编译. 通过exec和eval可以执行我们的代码
     
    code = '''
    for i in range(10):
        if i % 2 == 0:
            print(i)
    '''
     
     
    = compile(code, "", "exec") # 预加载代码
    # exec
    exec(c) # 运行代码
     
    # 可以使用complie写一个编程大赛.
  • 相关阅读:
    文本特殊符号汇集
    十大编程算法助程序员走上高手之路
    单例模式(Singleton)
    flink time and watermark
    关于maven依赖关系的问题
    幂等
    乐观锁和悲观锁的一个例子
    Elasticsearch logstash filter
    ELK filebeat的安装
    使用 Python 验证数据集中的体温是否符合正态分布
  • 原文地址:https://www.cnblogs.com/heheda123456/p/10202014.html
Copyright © 2011-2022 走看看