<p>你所要求的可以像这样实现,但我当然不建议这样做:</p>
<pre><code>>>> x = 10
>>> def foo(func, string_of_var):
globals()[string_of_var] = func(globals()[string_of_var])
>>> def bar(x):
return x * 2
>>> foo(bar, 'x')
>>> x
20
</code></pre>
<p>至于改变它的政治公众人物,如果有一个我怀疑它会得到批准。调用这样一个隐式更改值的函数违背了Python的禅意:</p>
<pre><code>The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit. <==== Relevant line
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules. <==== also probably relevant
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one and preferably only one obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea. <==== And this one for good measure
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea let's do more of those!
</code></pre>
<p>这也可能需要大量的工作,而不会给语言增加太多内容。Python没有<code>++</code>/<code> </code>表示<a href="https://stackoverflow.com/questions/3654830/why-are-there-no-and-operators-in-python">this reason</a>。当<code>x += 1</code>达到同样的效果时,添加它可能需要更多的工作。在这里也是如此,在调用函数时,需要几个人做大量的工作来节省一些按键。你知道吗</p>