Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93177

Re: Can anybody explain the '-' in a 2-D creation code?

Newsgroups comp.lang.python
Date 2015-06-25 18:24 -0700
References <e90e10c2-6762-4636-9e05-1f96c7c0b2c2@googlegroups.com>
Message-ID <7dea671b-cc91-467b-b0ea-137923032ce3@googlegroups.com> (permalink)
Subject Re: Can anybody explain the '-' in a 2-D creation code?
From André Roberge <andre.roberge@gmail.com>

Show all headers | View raw


On Thursday, 25 June 2015 22:07:42 UTC-3, fl  wrote:
> Hi,
> 
> I read Ned's tutorial on Python. It is very interesting. On its last
> example, I cannot understand the '_' in:
> 
> 
> 
> board=[[0]*8 for _ in range(8)]
> 
> 
> I know  '_' is the precious answer, but it is still unclear what it is
> in the above line. Can you explain it to me?

'_' is the previous answer ONLY when using the read-eval-print-loop interpreter.

Here, it is the "name" of a variable; since we don't care about the particular name (it is used just for looping a fixed number of times), the common practice of using '_' has been used.  As you will have noted (since it confused you), '_' doesn't seem to designate anything of interest - unlike a variable name like 'string_index' or 'character', etc.

Sometimes, people will use the name "dummy" instead of '_', with the same idea in mind.
> 
> 
> Thanks,

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can anybody explain the '-' in a 2-D creation code? fl <rxjwg98@gmail.com> - 2015-06-25 18:07 -0700
  Re: Can anybody explain the '-' in a 2-D creation code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-26 02:23 +0100
    Re: Can anybody explain the '-' in a 2-D creation code? fl <rxjwg98@gmail.com> - 2015-06-25 18:40 -0700
      Re: Can anybody explain the '-' in a 2-D creation code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-26 03:27 +0100
  Re: Can anybody explain the '-' in a 2-D creation code? André Roberge <andre.roberge@gmail.com> - 2015-06-25 18:24 -0700
  Re: Can anybody explain the '-' in a 2-D creation code? Atnakus Arzah <atnakus.arzah@gmail.com> - 2015-06-25 18:29 -0700
  Re: Can anybody explain the '-' in a 2-D creation code? Gary Herron <gary.herron@islandtraining.com> - 2015-06-25 18:18 -0700

csiph-web