Basic question about speed/coding style/memory

Jan Riechers janpeterr at
Sat Jul 21 10:13:02 CEST 2012

On 21.07.2012 11:02, Andrew Berg wrote:
> On 7/21/2012 2:33 AM, Jan Riechers wrote:
>> Block
>> ...
>> versus this block:
>> ...
>> Now, very briefly, what is the better way to proceed in terms of
>> execution speed, readability, coding style?
> Using if/else is the most readable in the general sense. Using return
> (or break or continue as applicable) in this manner would indicate (at
> least to me) that it's an exceptional or otherwise special case and that
> the function can't do what it's supposed to. In that case, I would try
> to catch an exception rather than use if/else whenever possible. I
> highly doubt there is a significant performance difference between them.

Hello Andrew,

Your answer is right, in other circumstances I also would stick to 
try/except, break-statements in loops and so forth.
But the question was a bit more elementary.

Cause, as I understand the interpreter chooses either the "else" (1st 
block) or just proceeds with following code outside the if.

So if there is some overhead in some fashion in case we don't offer the 
else, assuming the interpreter has to exit the evaluation of the 
"if"-statement clause and return to a "normal parsing code"-state 
outside the if statement itself.

I hope this explanation makes more sense in what I want to ask ;)


More information about the Python-list mailing list