美文网首页
python函数“转移”

python函数“转移”

作者: 青哥DevOps | 来源:发表于2020-01-05 00:10 被阅读0次

上代码

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

bbb

通过上面的小例子,你就可以看出,函数内的返回值可以转换!
_code_对象的属性是只读,但是_code_属性本身不变!

相关文章

网友评论

      本文标题:python函数“转移”

      本文链接:https://www.haomeiwen.com/subject/kpqqactx.html