Path: csiph.com!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'interpreter': 0.04; 'true,': 0.04; 'subject:question': 0.08; 'python': 0.09; 'coding,': 0.09; 'skip:# 30': 0.09; 'programmer': 0.11; 'block:': 0.16; 'checks:': 0.16; 'conditional': 0.16; 'execute,': 0.16; 'subject:coding': 0.16; 'jan': 0.18; 'skip:" 30': 0.20; 'not,': 0.21; '3.x': 0.22; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'coding': 0.27; 'prevent': 0.27; 'question': 0.27; 'execution': 0.27; 'subject:/': 0.28; 'run': 0.28; 'that.': 0.30; 'basic': 0.30; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'that,': 0.34; 'but': 0.36; 'thank': 0.36; 'does': 0.37; 'fact': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'easy': 0.60; 'first': 0.61; 'header :Reply-To:1': 0.68; 'friendly': 0.71; 'reply-to:no real name:2**0': 0.72; 'briefly,': 0.84; 'subject:Basic': 0.84; 'to:name:python': 0.84; 'do:': 0.91 Date: Sat, 21 Jul 2012 10:33:27 +0300 From: Jan Riechers User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Python Subject: Basic question about speed/coding style/memory Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: janpeterr@freenet.de List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342856185 news.xs4all.nl 6986 [2001:888:2000:d::a6]:40108 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25725 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