Python下划线作为函数参数 [英] Python underscore as a function parameter
问题描述
我有一个特定于python的问题.单个下划线_
作为参数意味着什么?
我有一个调用hexdump(_)
的函数. _从未定义,因此我想它有一些特殊的价值,我找不到在网络上告诉我含义的参考.如果您能告诉我,我会很高兴.
I have a python specific question. What does a single underscore _
as a parameter means?
I have a function calling hexdump(_)
. The _ was never defined, so I guess it has some special value, I could not find a reference telling me what it means on the net. I would be happy if you could tell me.
推荐答案
在Python shell中,下划线(_
)表示shell中最后一个求值表达式的结果:
In Python shells, the underscore (_
) means the result of the last evaluated expression in the shell:
>>> 2+3
5
>>> _
5
在IPython中也有_2
,_3
等,但在原始Python解释器中没有.据我所知,它在Python源代码中没有特殊含义,因此,我猜它是在您的代码中定义的,如果它运行时没有错误.
There's also _2
, _3
and so on in IPython but not in the original Python interpreter. It has no special meaning in Python source code as far as I know, so I guess it is defined somewhere in your code if it runs without errors.
这篇关于Python下划线作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!