gpt4 book ai didi

Python 和封闭变量

转载 作者:太空狗 更新时间:2023-10-29 22:02:03 26 4
gpt4 key购买 nike

<分区>

看看这段代码:

def closure():
value = False

def method_1():
value = True

def method_2():
print 'value is:', value

method_1()
method_2()

closure()

我希望它打印“Value is: True”,但它没有。为什么会这样,解决方案是什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com