Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93173 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2015-06-25 18:07 -0700 |
| Last post | 2015-06-25 18:18 -0700 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-06-25 18:07 -0700 |
| Subject | Can anybody explain the '-' in a 2-D creation code? |
| Message-ID | <e90e10c2-6762-4636-9e05-1f96c7c0b2c2@googlegroups.com> |
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? Thanks,
[toc] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-06-26 02:23 +0100 |
| Message-ID | <mailman.92.1435281823.3674.python-list@python.org> |
| In reply to | #93173 |
On 26/06/2015 02:07, 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? > > > Thanks, > Lots of people could carry on explaining things to you, but you don't appear to be making any attempt to do some research before posing your questions, so how about using a search engine? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2015-06-25 18:40 -0700 |
| Message-ID | <88b1f3fe-2a0f-408d-8dd6-283cd26e48f8@googlegroups.com> |
| In reply to | #93176 |
On Thursday, June 25, 2015 at 6:24:07 PM UTC-7, Mark Lawrence wrote: > On 26/06/2015 02:07, 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? > > > > > > Thanks, > > > > Lots of people could carry on explaining things to you, but you don't > appear to be making any attempt to do some research before posing your > questions, so how about using a search engine? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Excuse me. On one hand, I am busying on cram these Python stuff quickly for a position. On the other hand, the search seems to me needing a little skill to get the goal I hope. I would really appreciate if someone can give an example on what phrase to use in the search. I am not a lazy guy. Thanks to all the response.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-06-26 03:27 +0100 |
| Message-ID | <mailman.97.1435285805.3674.python-list@python.org> |
| In reply to | #93178 |
On 26/06/2015 02:40, fl wrote: > On Thursday, June 25, 2015 at 6:24:07 PM UTC-7, Mark Lawrence wrote: >> On 26/06/2015 02:07, 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? >>> >>> >>> Thanks, >>> >> >> Lots of people could carry on explaining things to you, but you don't >> appear to be making any attempt to do some research before posing your >> questions, so how about using a search engine? >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > Excuse me. On one hand, I am busying on cram these Python stuff quickly for > a position. On the other hand, the search seems to me needing a little > skill to get the goal I hope. I would really appreciate if someone can give > an example on what phrase to use in the search. I am not a lazy guy. > Thanks to all the response. > http://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | André Roberge <andre.roberge@gmail.com> |
|---|---|
| Date | 2015-06-25 18:24 -0700 |
| Message-ID | <7dea671b-cc91-467b-b0ea-137923032ce3@googlegroups.com> |
| In reply to | #93173 |
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,
[toc] | [prev] | [next] | [standalone]
| From | Atnakus Arzah <atnakus.arzah@gmail.com> |
|---|---|
| Date | 2015-06-25 18:29 -0700 |
| Message-ID | <mailman.103.1435302561.3674.python-list@python.org> |
| In reply to | #93173 |
On Thu, Jun 25, 2015 at 06:07:30PM -0700, 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? Its just a variable whose value isn't used in this specific expression, you could use 'x', 'y', or any other valid variable name there and it should work. -- Atnakus Arzah <atnakus.arzah@gmail.com> When in doubt, have a cookie!
[toc] | [prev] | [next] | [standalone]
| From | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| Date | 2015-06-25 18:18 -0700 |
| Message-ID | <mailman.102.1435302561.3674.python-list@python.org> |
| In reply to | #93173 |
On 06/25/2015 06:07 PM, 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? > > > Thanks, He uses _ to indicate a variable whose name and value he does not care about, but it *is* a valid variable name. He could have used ... for i in range ... or ... for unused_variable in range ... This is a valid, though probably unclear, use of that same name: >>> _ = 123 >>> print(_) 123 >>> Gary Herron
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web