Re: Coding style
- From: "Patrick Maupin" <pmaupin@xxxxxxxxx>
- Date: 17 Jul 2006 19:44:31 -0700
PTY wrote:
It looks like there are two crowds, terse and verbose. I thought terse
is perl style and verbose is python style. BTW, lst = [] was not what
I was interested in :-) I was asking whether it was better style to
use len() or not.
It's not canonical Python to use len() in this case. From PEP 8:
- For sequences, (strings, lists, tuples), use the fact that empty
sequences are false.
Yes: if not seq:
if seq:
No: if len(seq)
if not len(seq)
The whole reason that a sequence supports testing is exactly for this
scenario. This is not an afterthought -- it's a fundamental design
decision of the language.
Regards,
Pat
.
- References:
- Coding style
- From: PTY
- Re: Coding style
- From: rurpy
- Re: Coding style
- From: Bob Greschke
- Re: Coding style
- From: PTY
- Coding style
- Prev by Date: range() is not the best way to check range?
- Next by Date: Re: range() is not the best way to check range?
- Previous by thread: Re: Coding style
- Next by thread: pyKML: where to get it?
- Index(es):
Relevant Pages
|