Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'languages,': 0.04; 'true,': 0.04; 'subject:Python': 0.05; 'false.': 0.07; 'javascript,': 0.07; 'nested': 0.07; 'null,': 0.07; 'python': 0.09; '(module)': 0.09; '22,': 0.09; 'braces': 0.09; 'declarations': 0.09; 'python:': 0.09; 'restriction': 0.09; 'special,': 0.09; 'do,': 0.15; '(but': 0.15; 'blocks': 0.16; 'boolean': 0.16; 'chris,': 0.16; 'context;': 0.16; 'curly': 0.16; 'earlier.': 0.16; 'editor,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'infinitely': 0.16; 'overwriting': 0.16; 'personally,': 0.16; 'scope,': 0.16; 'tuples,': 0.16; 'zero,': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'variables': 0.17; 'feb': 0.19; '(not': 0.20; 'variable': 0.20; 'file.': 0.20; 'earlier': 0.21; 'facility': 0.22; "python's": 0.23; "haven't": 0.23; "i've": 0.23; 'specifically': 0.24; 'header :In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; 'see,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.27; 'declared': 0.29; 'indentation': 0.29; 'served': 0.29; 'unlikely': 0.29; 'fri,': 0.30; 'function': 0.30; 'code': 0.31; 'generally': 0.32; 'strict': 0.33; 'true.': 0.33; 'zero': 0.33; 'to:addr:python- list': 0.33; 'equal': 0.33; 'languages': 0.33; 'point.': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'whatever': 0.35; 'false': 0.35; 'received:209.85.220': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; "didn't": 0.36; 'test': 0.36; 'problems': 0.36; 'one,': 0.37; 'does': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'there,': 0.38; 'system.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'decision': 0.60; 'skip:u 10': 0.60; 'most': 0.61; 'evaluate': 0.62; 'solve': 0.62; 'more': 0.63; 'within': 0.64; 'legal': 0.65; 'facilities': 0.69; 'special': 0.73; '2013': 0.84; 'standing': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=ZIHrHbGTzTLI28i5VH94hdWeR8rh9lQggMH0Yxr/yoM=; b=zspkrUHmE0ijeELn0UOHtXr00XioWfzVngG0X0sR3uIcWc/prfaxLghPXs23+hmLuK S+Ar4+ato1MRMfv+74/M1bsvuJWlEHv/vlfR1ELtwIv/eRTVe2NPsnZQjASyhZBiB8b2 7agmimX7LBbVof5UYQc4skVl/MqOmUzJT0pDIvxDYsssjunxZz4NxfD/Zccd9ANf06KC sinWKds3z7rFrAm4w12GDajBOAPdDNcCuQZJaSSsQO3sB+nozuYKcUaLfq/4Vz3B5wc/ 0vktct0CRkQzt/RNPXbnqg6P/fYJn2kMrTPPznTL+IBgXivvB3cY9aCbqvdmt/QAkpNG Z0rA== MIME-Version: 1.0 X-Received: by 10.52.29.209 with SMTP id m17mr23892368vdh.111.1361488887445; Thu, 21 Feb 2013 15:21:27 -0800 (PST) In-Reply-To: <5c262e95-b3a8-4f2a-b752-84b30bf4f81e@googlegroups.com> References: <5c262e95-b3a8-4f2a-b752-84b30bf4f81e@googlegroups.com> Date: Fri, 22 Feb 2013 10:21:27 +1100 Subject: Re: Python Newbie From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361488895 news.xs4all.nl 6912 [2001:888:2000:d::a6]:60513 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39487 On Fri, Feb 22, 2013 at 9:40 AM, wrote: > Thanks to all for quick relies. > > Chris, you are (almost) spot on with the if blocks indentation. This is w= hat I do, and it has served me well for 15 years. > > code > code > > if (some condition) > { > code > code > } > I understand you have the freedom to do that in most languages, but that's simply a restriction of Python: you have to use a more conventional indentation system. Personally, I don't see the 'if' as being special here, and the body of it (which IS special, as it may or may not be executed) is already standing out. > I am nervous about using variables "out of the blue", without having to d= eclare them. For example, when I write "i =3D 0" it is perfectly OK to Pyth= on without 'i' being declared earlier. How do I know that I haven't used th= is variable earlier and I am unintentionally overwriting the value? I find = I constantly have to use the search facility in the editor, which is not fu= n. > > You see, Javascript, for one, behaves the same way as Python (no variable= declaration) but JS has curly braces and you know the variable you have ju= st used is limited in scope to the code within the { }. With Python, you ha= ve to search the whole file. That's a fair point. The elision of variable declarations is a design decision that Python is unlikely to reverse, and it happens to be one I disagree with. But it's there, so when I code Python, I accept it :) There are other languages similar to Python that have strict variable declarations, and with them the awesomeness that is infinitely nested scopes; Python just has global (module) scope and function scope, plus 'nonlocal' which can solve some problems (but I've yet to find it do so without damaging code clarity). > What about Python's ambiguity? > For example, in C you would write > > if (myVar !=3D 0) > do something > > in Python, this is legal > > if (not myVar): > do something > > What does this mean? Is it a test for myVar being equal to zero or a test= for null, or else? Python has a state called "truthiness". Generally speaking, something with content is true, and something without content is false. The None singleton, empty lists, empty tuples, the integer 0, and a regular expression result that didn't match, all evaluate as False in a boolean context; most other things evaluate as True. If you specifically care if it's not zero, you ask if it's not zero; if you want to know if it's falsy, you check "not X". The facilities are there to do whatever you want. ChrisA