Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25928
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-07-23 14:42 -0700 |
| References | <mailman.2364.1342856185.4697.python-list@python.org> |
| Subject | Re: Basic question about speed/coding style/memory |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| Message-ID | <mailman.2503.1343079777.4697.python-list@python.org> (permalink) |
Jan Riechers於 2012年7月21日星期六UTC+8下午3時33分27秒寫道: > Hello Pythonlist, > > I have one very basic question about speed,memory friendly coding, and > coding style of the following easy "if"-statement in Python 2.7, but Im > sure its also the same in Python 3.x > > Block > #---------------------------------- > if statemente_true: if an evaluated expression result is non-zero, then > doSomething() > else: # execute this block if the expression evaluated as zero > doSomethingElseInstead() > > #---------------------------------- > > versus this block: > #---------------------------------- > if statement_true: > doSomething() > return > > doSomethingElseInstead() > > #---------------------------------- > > > I understand the first pattern that I tell the interpreter to do: > Check if the conditional is true, run "doSomething()" else go inside the > else block and "doSomethingElseInstead()". > > while the 2nd does only checks: > doSomething() if statement_true, if not, just go directly to > "doSomethingElseInstead() > > > Now, very briefly, what is the better way to proceed in terms of > execution speed, readability, coding style? > Letting out the fact that, in order to prevent > "doSomethingElseInstead"-Block to execute, a return has to provided. > > Thank you for reading and hope someone brings light into that. > > Your fellow python programmer > Jan Well, the C-style branching is inherited in python. Expressions and statements are different.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Basic question about speed/coding style/memory Jan Riechers <janpeterr@freenet.de> - 2012-07-21 10:33 +0300
Re: Basic question about speed/coding style/memory Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-21 09:06 +0000
Re: Basic question about speed/coding style/memory Jan Riechers <janpeterr@freenet.de> - 2012-07-21 12:32 +0300
Re: Basic question about speed/coding style/memory Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-21 21:31 -0400
Re: Basic question about speed/coding style/memory Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-21 21:19 +0200
Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:42 -0700
Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:42 -0700
csiph-web