'_' and '__'
Ben Finney
ben+python at benfinney.id.au
Sat May 26 20:36:30 EDT 2018
Mike McClain <mike.junk.46 at att.net> writes:
> Steven D'Aprano and Ben Finney used these '_' and '__'.
> Steve said, "[[] for _ in range(5)]".
> Ben said, "[ [] for __ in range(5) ]".
>
> These aren't listed separately in the index
That's right, the names ‘_’ and ‘__’ have no special meaning in
Python-the-language so they don't appear in the index.
Steven and I both used those respective names to communicate “never
going to use this value but the syntax requires a name here”.
> where might I find written discussion of these?
I find Nick Coghlan's answer on StackOverflow
<URL:https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python/5893946#5893946>
to be especially helpful.
Nick also explains that, because the name ‘_’ has too many conventional
meanings already, the name ‘__’ is better for “don't need this value but
I am required to specify a name”.
--
\ “The double standard that exempts religious activities from |
`\ almost all standards of accountability should be dismantled |
_o__) once and for all.” —Daniel Dennett, 2010-01-12 |
Ben Finney
More information about the Python-list
mailing list