On Tue, Dec 5, 2017 at 10:50 AM, Rick Johnson <rantingrickjohn...@gmail.com> wrote: > Chris Angelico wrote: >> <rantingrickjohn...@gmail.com> wrote: >> > Terry Reedy wrote: >> > >> > [...] >> > >> >> try: >> >> item = seq[n] >> >> except IndexError >> >> do_without_item() >> >> else: >> >> process(item) >> >> >> >> item = seq[n:n+1] >> >> if item: >> >> process(item) >> >> else: >> >> do_without_item() >> >> >> >> Many prefer the second. >> > >> > And they'll prefer it even more when they realize the entire ELSE >> > clause of your latter example is superfluous. >> >> ... how is it superfluous? > > If the only purpose of an if/else logic structure is to > process an arbitrary value _only_ when that value is > "truthy", and futhermore, the else clause does nothing of > any significance (and in the example provided, appears to > be nothing but a placeholder for dead code) then why > bother writing the else clause in the first place?
Ahhh, I see how it is. You didn't run the code, ergo you don't understand it. Makes perfect sense. :) Hint: Truthiness is fairly clearly defined here, regardless of the value of item. ChrisA -- https://mail.python.org/mailman/listinfo/python-list