roy at panix.com
Mon Feb 24 02:28:49 CET 2014
In article <mailman.7297.1393204171.18130.python-list at python.org>,
Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> On 24/02/2014 00:55, alex23 wrote:
> > On 23/02/2014 3:43 PM, Scott W Dunning wrote:
> >> I had a question regarding functions. Is there a way to call a
> >> function multiple times without recalling it over and over. Meaning
> >> is there a way I can call a function and then add *5 or something like
> >> that?
> > The same way you repeat anything in Python: with a loop construct.
> > for _ in range(5):
> > func()
> For the benefit of newbies, besides the obvious indentation error above,
> the underscore basically acts as a dummy variable. I'll let the
> language lawyers give a very detailed, precise description :)
As far as I know, it's purely convention. _ is a legal variable name in
Python, and the convention is that unpacking something into _ means, "I
don't care about that value". It's also used to ignore several values:
_, _, foo, bar, _ = blah
unpacks a 5-tuple, of which you only care about the 3rd and 4th values.
More information about the Python-list