首页 > 编程语言 > 详细

Python临时笔记

时间:2017-08-13 22:04:57      阅读:223      评论:0      收藏:0      [点我收藏+]

动态语言python的特性

python2  输入一个匿名函数直接执行

# coding=utf-8
def Test(a, b, func):
    result = func(a, b)
    return result

func_new = input("please input a fun::")    #please input a fun::lambda x,y:x+y
print(Test(10, 20, func_new))#30

python3 会把input输入进去的东西全部转换成字符串  因此需要eval方法转换 

def Test(a, b, func):
    result = func(a, b)
    return result

func_new = input("please input a fun::")  # python3中input接受的值全部变成string类型   please input a fun::lambda x,y:x+y
func_new = eval(func_new)  # 执行字符串的python语句  
print(Test(10, 20, func_new)) #30

 

Python临时笔记

原文:http://www.cnblogs.com/kanekiken/p/7354984.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!