Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25725
| Date | 2012-07-21 10:33 +0300 |
|---|---|
| From | Jan Riechers <janpeterr@freenet.de> |
| Subject | Basic question about speed/coding style/memory |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2364.1342856185.4697.python-list@python.org> (permalink) |
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: doSomething() else: 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
Back to comp.lang.python | Previous | Next — Next 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