Basic question about speed/coding style/memory

Jan Riechers janpeterr at freenet.de
Sat Jul 21 03:33:27 EDT 2012


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



More information about the Python-list mailing list