码迷,mamicode.com
首页 > 编程语言 > 详细

Python临时笔记

时间:2017-08-13 22:14:23      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:please   lam   func   一个   log   return   class   utf-8   pre   

动态语言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临时笔记

标签:please   lam   func   一个   log   return   class   utf-8   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!