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

python函数“转移”

时间:2017-05-12 22:03:20      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:python   return   

废话不多说,直接上代码!

def test1():
    return "aaa"
def test2():
    return "bbb"
test1().__code__ = test2().__code__
print test1()

bbb

通过上面的小例子,你就可以看出,函数内的返回值可以转换!

####

__code__对象的属性是只读,但是__code__属性本身不变!

python函数“转移”

标签:python   return   

原文地址:http://jeaner.blog.51cto.com/9460854/1925163

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