<分区>
我在 Python 中使用 type()
方法,遇到了这个:
>>> type(_)
<type 'type'>
下划线 ( _ ) 字符的“类型”是 type
本身。这到底是什么意思?
标签 python python-2.7
<分区>
我在 Python 中使用 type()
方法,遇到了这个:
>>> type(_)
<type 'type'>
下划线 ( _ ) 字符的“类型”是 type
本身。这到底是什么意思?
最佳答案
在 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'>
关于python - Python中下划线字符的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32486163/