Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2a.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.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'operator': 0.03; 'cc:addr :python-list': 0.11; 'jan': 0.12; 'assume': 0.14; 'behave': 0.16; 'bounds': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'student': 0.16; 'wrote:': 0.18; 'code.': 0.18; "python's": 0.19; 'cc:addr:python.org': 0.22; '31,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"do': 0.31; 'stuff': 0.32; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'crazy': 0.36; 'awesome': 0.38; 'maximum': 0.63; 'within': 0.65; 'between': 0.67; '20,': 0.68; 'all!': 0.84; 'subject:True': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=tqb48DKUZIfjUNsGioYdusnH5B84l7iXVWnFIkH9Zwk=; b=B+vtadt4dLKs/Bn4gVRiqz/e4W9x+NYYg4/0Q3Nmprxai88PNhEyd+z9fU1OZCBCpD pbZ4DlpRNz8XgYoczikdQkqsC7nZ+pJ0kcf06Uxj55bPBGKdpEO5f+WHi9POeROT69Pk 4uKpZLTUQazNcdSy8fi1cL/LIa0S+EDM9/hI2mGpMx/Cnp8A08Q8w892TwZ07cbcIzTq ZmQh9KgCkNDdgTdwuLhiJYXxWv2ZlLngZEFZfk77yPuFf2tXMd/vqeeStOUQGFmm6LMA 4D/jVzQzAjfn+1WqOgwdzrS+WbNRJv6z/y3ivUUEKU8zAyhXhND745UpLEtal6JhwfLa f8aQ== MIME-Version: 1.0 X-Received: by 10.68.108.194 with SMTP id hm2mr14695031pbb.22.1391090144461; Thu, 30 Jan 2014 05:55:44 -0800 (PST) In-Reply-To: <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Date: Fri, 31 Jan 2014 00:55:44 +1100 Subject: Re: 1 > 0 == True -> False From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391090148 news.xs4all.nl 2870 [2001:888:2000:d::a6]:57225 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65002 On Fri, Jan 31, 2014 at 12:40 AM, Thibault Langlois wrote: > The recommendations to student are 1) do not assume True == 1 and do not use operator chaining. Not "do not use", but "do not misuse". Python's operator chaining is awesome for bounds checking: if 3 < x < 20: print("x is between 3 and 20, exclusive") You can even, since it short-circuits, do crazy stuff like: x = random.randrange(30) if int(input("Min: ")) < x < int(input("Max: ")): print("It's within those bounds.") It won't ask for a maximum if it's already failed to be within the minimum. (Okay, don't do this one. Not good code. Heh.) But don't use operator chaining when you don't mean it to behave that way. That's all! ChrisA