Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56636
| Date | 2013-10-10 19:47 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Python's and and Pythons or |
| References | (1 earlier) <a471eecd-2e9f-4d32-8825-bdc088a0ecb0@googlegroups.com> <CAPTjJmrnw9kSuCG0cJrNeGF7A=ge-R0izj75J1QTTBHkPtNuyw@mail.gmail.com> <l35lqd$jh2$1@ger.gmane.org> <5256ACAB.7050809@stoneleaf.us> <l37kvb$ech$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.979.1381459623.18130.python-list@python.org> (permalink) |
On 10/10/2013 06:41 PM, Terry Reedy wrote: > On 10/10/2013 9:33 AM, Ethan Furman wrote: > >> On 10/10/2013 12:43 AM, Terry Reedy wrote: > >>> On 10/10/2013 2:45 AM, Chris Angelico wrote: >>>> first_element = some_list[0] # Oops, may crash > >>> some_list[0:1] always works, and sometimes is usable, but you still >>> cannot index the slice. > >> Not if some_list is None, False, or another non-indexable type. > > Did you really not understand that some_list is intended to be a list? Just like my_string, for instance, would be a > string? Chris's statement further specifies some_list as a list that is expected to not be empty, but might be -- so one > has to guard against the possibility. I understood it just fine. I'm also aware that at some point, in some program, it will be None (and it won't be a bug ;). > The trick of slicing instead of indexing in this context is not obvious to everyone learning Python. Most other > languages only have indexing. I learned the trick years ago when someone posted it on this list. It's a good trick, I use it myself. -- ~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 16:54 -0700
Re: Python's and and Pythons or Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-10 00:36 +0000
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 12:13 +1100
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:12 -0700
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 17:45 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-09 23:46 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 03:43 -0400
Re: Python's and and Pythons or Chris Angelico <rosuav@gmail.com> - 2013-10-10 19:03 +1100
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 06:33 -0700
Re: Python's and and Pythons or Terry Reedy <tjreedy@udel.edu> - 2013-10-10 21:41 -0400
Re: Python's and and Pythons or Ethan Furman <ethan@stoneleaf.us> - 2013-10-10 19:47 -0700
Re: Python's and and Pythons or Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-09 23:55 -0700
csiph-web