一堆内置函数 exec 没有返回值 eval 有返回值 compile 编译代码 sorted(iterable, key=function排序规则, reverse=翻转) map(function, iterable) filter(function, iterable) 匿名函数 : lambda 参数: 返回值
# 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)'''c = compile(code, "", "exec") # 预加载代码# execexec(c) # 运行代码# 可以使用complie写一个编程大赛.
思维导图网址
https://www.processon.com/mindmap/5c10bcf5e4b091f1bf714905