我刚刚开始学习Python
。
我指的是 http://docs.python.org/tutorial/ 上的教程
引用关于变量_
的教程
This variable should be treated as read-only by the user. Don’t explicitly assign a value to it — you would create an independent local variable with the same name masking the built-in variable with its magic behavior.
假设我通过将变量分配给像 _ = 10
这样的数字来屏蔽该变量。是否可以再次取消屏蔽以将其引用到最后打印的表达式?如果是这样,怎么办?
谢谢。
最佳答案
del _
取消屏蔽重新定义的 _
:
>>> 7*2
>>> _
14
>>> _ = 88
>>> _
88
>>> 1+2
3
>>> _
88
>>> del _
>>> _
88
>>> 1+2
3
>>> _
3
关于python - 取消屏蔽最后打印的表达式变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5233885/