Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61255
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: One liners |
| Date | 2013-12-07 16:02 -0500 |
| References | (4 earlier) <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <roy-10E325.22270006122013@news.panix.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> <qotfvq4suj6.fsf@ruuvi.it.helsinki.fi> <l7vhem$tf1$1@dont-email.me> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3707.1386450167.18130.python-list@python.org> (permalink) |
On 12/7/2013 11:13 AM, Rotwang wrote: > On 07/12/2013 12:41, Jussi Piitulainen wrote: >> [...] >> >> if tracks is None: >> tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? The 'extra' line is not necessary, as one can write if tracks is None: tracks = [] # or something I prefer this because it exactly expresses what one want done. The other branch else: tracks = tracks is superfluous and to me unaesthetic. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-06 17:20 -0700
Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 02:28 +0000
Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-07 13:40 +1100
Re: One liners Roy Smith <roy@panix.com> - 2013-12-06 22:27 -0500
Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-07 15:06 +1100
Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 11:27 +0000
Re: One liners Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-07 14:41 +0200
Re: One liners Rotwang <sg552@hotmail.co.uk> - 2013-12-07 16:13 +0000
Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 16:25 +0000
Re: One liners Rotwang <sg552@hotmail.co.uk> - 2013-12-08 02:23 +0000
Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 09:26 -0700
Re: One liners Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-07 19:49 +0200
Re: One liners Terry Reedy <tjreedy@udel.edu> - 2013-12-07 16:02 -0500
Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 09:56 -0700
Re: One liners rusi <rustompmody@gmail.com> - 2013-12-07 09:10 -0800
Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 10:02 -0700
csiph-web