Manas Chaturvedi Manas Chaturvedi - 2 years ago 98
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?

Answer Source

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'>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download