Manas Chaturvedi Manas Chaturvedi - 1 year ago 58
Python Question

Type of an underscore character in Python

I was playing with the

method in Python, and came across this:

>>> type(_)
<type 'type'>

The 'type' of the underscore( _ ) character is
itself. What does that even mean?


Inside python interpreter, _ is a special variable that returns output from previous line, so depending on the last line type of that variable value could be different.

For example,

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