Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; '22,': 0.09; '[0,': 0.09; 'literal': 0.09; 'semantic': 0.09; 'subject:test': 0.09; 'thx': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'ast': 0.16; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operator.': 0.16; 'readable': 0.16; 'subscripting': 0.16; 'ternary': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; "i've": 0.25; 'compare': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'is?': 0.30; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'post.': 0.31; 'though.': 0.31; 'thanks!': 0.32; 'there,': 0.34; 'problem': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'list': 0.37; 'pm,': 0.38; 'blank': 0.60; 'skip:6 10': 0.63; 'excessive': 0.84; 'subject::': 0.85; 'not:': 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=j3+RxwwqNR/ISkDjK34JoJ3bWVa++qEMySjfZpJ3Ic0=; b=Hb0mKljWxxQR2MwNLq2pSx+UJg077mNPTn/WYRCFTjscU8ljuGaWXflpJWjqjTcf3a WPNPYxQZ48YRmee6xdR1J+J7y19dqbskheemdiz+Z+hk02Xf7pS/gzeKIilfLhUcyKz4 XWwGRTMX38Vv1+NJ7TAEyKYa4kIyt1OwguXD6coUvjRjR/dDCIpeNxV7BM80aCZNUuql bl3x1o5WfrNuF0o30sucK9cWVt4b52EqfNDgiltQuFfwYuvdULZ6fu89/itO2GVv3EU/ 31v4nVczAXGRk6RjxCcPximRhKxILgZn4QuF04vp8lifhd4jOQ05ey22ccrFzWOFPdVg b99w== MIME-Version: 1.0 X-Received: by 10.42.37.138 with SMTP id y10mr3351292icd.26.1413969355612; Wed, 22 Oct 2014 02:15:55 -0700 (PDT) In-Reply-To: <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> Date: Wed, 22 Oct 2014 20:15:55 +1100 Subject: Re: (test) ? a:b 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413969362 news.xs4all.nl 2864 [2001:888:2000:d::a6]:53010 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79422 On Wed, Oct 22, 2014 at 8:05 PM, wrote: > Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu: >> Hello >> >> >> >> Is there in Python something like: >> >> >> >> j = (j >= 10) ? 3 : j+1; >> >> >> >> as in C language ? >> >> >> >> thx > > without not: > j = [j+1, 3][j>=10] > with not: > j = [3, j+1][not (j>=10)] There's a distinct semantic difference there, though. Compare these: /* C */ int x = (y != 0) ? 65536/y : 0; # Python x = 65536/y if y else 0 # Python, your way x = [0, 65536/y][y!=0] Do you see where the problem is? Plus, subscripting a literal list is far less readable than the ternary operator. Also: Please can you avoid Google Groups, or if you must use it, please at least clean up the excessive blank lines before you post. I've left them so you can see what we have to cope with. Thanks! ChrisA