Python中下划线字符的类型

Man*_*edi 4 python python-2.7

我正在使用type()Python中的方法,并遇到了这个:

>>> type(_)
<type 'type'>
Run Code Online (Sandbox Code Playgroud)

下划线(_)字符的"类型" type本身就是.那有什么意思?

Mar*_*zek 9

在python解释器中,_是一个返回前一行输出的特殊变量,因此根据该变量值的最后一行类型可能会有所不同.

例如,

>>> type(_)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
>>> 1
1
>>> type(_)
<type 'int'>
>>> type(_)
<type 'type'>
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

576 次

最近记录:

9 年,4 月 前