dummy, underscore and unused local variables

Philip Semanchuk philip at semanchuk.com
Mon Jun 13 11:50:49 EDT 2011


On Jun 13, 2011, at 11:37 AM, Tim Johnson wrote:

> NOTE: I see much on google regarding unused local variables, 
> however, doing a search for 'python _' hasn't proved fruitful.

Yes, Google's not good for searching punctuation. But 'python underscore dummy OR unused' might work better.

> On a related note: from the python interpreter if I do
>>>> help(_) 
> I get 
> Help on bool object:
> 
> class bool(int)
> |  bool(x) -> bool
> ......
> I'd welcome comments on this as well.
> 

In the Python interpreter, _ gives you the results of the last expression. When you first start the interpreter, _ is undefined.

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

Help on bool object:

class bool(int)
 |  bool(x) -> bool


In your case when you asked for help(_), the last object you used must have been a bool.

> 
> :) I expect to be edified is so many ways, some
> of them unexpected.

That's the nice thing about this list!

Hope this helps
Philip





More information about the Python-list mailing list