下划线在Python的打印功能中起什么作用?

问题描述 投票:1回答:2

偶然我打印了类似的内容:

print(var, __)

我不明白正在产生什么。似乎会根据_____多长时间来获取历史记录项。我正在使用Pycharm。

python pycharm
2个回答
4
投票

__是变量名。

[____是不同的变量名称。

[print(var, __)打印var的内容,然后打印__的内容。

根据上下文,可以预先填写_ /__/ ___。在Jupyter笔记本中,这是前3个单元格的结果。


3
投票

您看到的可能是output caching of IPython

对于从操作返回的输出,类似于输入缓存已存在,但使用_而不是_i。只有这样的动作产生结果(例如,NOT分配)被缓存。如果你是熟悉Mathematica的IPython的_变量的行为与Mathematica的%变量。

以下变量始终存在:

    [_] (a single underscore): stores previous output, like Python’s default interpreter.
    [__] (two underscores): next previous.
    [___] (three underscores): next-next previous.
© www.soinside.com 2019 - 2024. All rights reserved.