Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25928

Re: Basic question about speed/coding style/memory

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 <dihedral88888@googlemail.com>
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 <mailman.2364.1342856185.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw
References <mailman.2364.1342856185.4697.python-list@python.org>
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 <dihedral88888@googlemail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.2503.1343079777.4697.python-list@python.org> (permalink)
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

Show key headers only | View raw


Jan Riechers於 2012年7月21日星期六UTC+8下午3時33分27秒寫道:
> Hello Pythonlist,
> 
> I have one very basic question about speed,memory friendly coding, and 
> coding style of the following easy &quot;if&quot;-statement in Python 2.7, but Im 
> sure its also the same in Python 3.x
> 
> Block
> #----------------------------------
> if statemente_true:

if an evaluated expression result is non-zero, then 


> 	doSomething()

> else: 
# execute this block if  the expression evaluated as zero
 
> 	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 &quot;doSomething()&quot; else go inside the 
> else block and &quot;doSomethingElseInstead()&quot;.
> 
> while the 2nd does only checks:
> doSomething() if statement_true, if not, just go directly to 
> &quot;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 
> &quot;doSomethingElseInstead&quot;-Block to execute, a return has to provided.
> 
> Thank you for reading and hope someone brings light into that.
> 
> Your fellow python programmer
> Jan

Well, the C-style branching is inherited in python.

Expressions and statements are different.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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