what does 'for _ in range()' mean?

David Eppstein eppstein at ics.uci.edu
Wed Jul 28 02:39:59 EDT 2004


In article <2moucmFo8dpdU1 at uni-berlin.de>,
 Jon Perez <jbperez808 at wahoo.com> wrote:

> I saw this code snippet:
> 
> sock.listen(20)
> for _ in range(20):
>      newsock, client_addr = sock.accept()
>      print "Client connected:", client_addr
>      data[newsock] = ""
> 
> why use _ for this example?  Is there any
> optimization to be had using it?
> 
> I know that in the interpreter _ means the
> last value calculated, but what does _ mean
> inside source code?

AFAIK it's just a variable like any other, but by convention it means 
that you don't intend to use that value, just read it and ignore it.

-- 
David Eppstein
Computer Science Dept., Univ. of California, Irvine
http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list