Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'interpreter': 0.04; 'true,': 0.04; 'expressions': 0.07; 'subject:question': 0.08; 'python': 0.09; 'branching': 0.09; 'coding,': 0.09; 'inherited': 0.09; 'skip:# 30': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'programmer': 0.11; 'block:': 0.16; 'checks:': 0.16; 'conditional': 0.16; 'execute,': 0.16; 'subject:coding': 0.16; 'jan': 0.18; 'not,': 0.21; '3.x': 0.22; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'coding': 0.27; 'prevent': 0.27; 'question': 0.27; 'execution': 0.27; 'subject:/': 0.28; 'run': 0.28; 'statements': 0.29; 'that.': 0.30; 'skip:& 30': 0.30; 'basic': 0.30; 'zero': 0.33; 'skip:& 20': 0.33; 'skip:d 20': 0.34; 'that,': 0.34; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'thank': 0.36; 'execute': 0.37; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'sure': 0.38; 'your': 0.60; 'easy': 0.60; 'first': 0.61; 'friendly': 0.71; 'briefly,': 0.84; 'different.': 0.84; 'subject:Basic': 0.84; 'do:': 0.91 Newsgroups: comp.lang.python Date: Mon, 23 Jul 2012 14:42:53 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.83.145 MIME-Version: 1.0 Subject: Re: Basic question about speed/coding style/memory From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343079777 news.xs4all.nl 6974 [2001:888:2000:d::a6]:55818 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25928 Jan Riechers=E6=96=BC 2012=E5=B9=B47=E6=9C=8821=E6=97=A5=E6=98=9F=E6=9C=9F= =E5=85=ADUTC+8=E4=B8=8B=E5=8D=883=E6=99=8233=E5=88=8627=E7=A7=92=E5=AF=AB= =E9=81=93=EF=BC=9A > Hello Pythonlist, >=20 > I have one very basic question about speed,memory friendly coding, and=20 > coding style of the following easy "if"-statement in Python 2.7= , but Im=20 > sure its also the same in Python 3.x >=20 > Block > #---------------------------------- > if statemente_true: if an evaluated expression result is non-zero, then=20 > doSomething() > else:=20 # execute this block if the expression evaluated as zero =20 > doSomethingElseInstead() >=20 > #---------------------------------- >=20 > versus this block: > #---------------------------------- > if statement_true: > doSomething() > return >=20 > doSomethingElseInstead() >=20 > #---------------------------------- >=20 >=20 > I understand the first pattern that I tell the interpreter to do: > Check if the conditional is true, run "doSomething()" else go i= nside the=20 > else block and "doSomethingElseInstead()". >=20 > while the 2nd does only checks: > doSomething() if statement_true, if not, just go directly to=20 > "doSomethingElseInstead() >=20 >=20 > Now, very briefly, what is the better way to proceed in terms of=20 > execution speed, readability, coding style? > Letting out the fact that, in order to prevent=20 > "doSomethingElseInstead"-Block to execute, a return has to prov= ided. >=20 > Thank you for reading and hope someone brings light into that. >=20 > Your fellow python programmer > Jan Well, the C-style branching is inherited in python. Expressions and statements are different.