Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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; 'subject:Python': 0.06; 'none:': 0.07; 'function,': 0.09; 'naturally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'jan': 0.12; 'awkward,': 0.16; 'callable': 0.16; 'func': 0.16; 'indexerror:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'slice.': 0.16; 'index': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'thu,': 0.19; 'example': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'list:': 0.30; "i'm": 0.30; 'crash': 0.31; 'maybe': 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'useful': 0.36; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'more': 0.64; 'effectively': 0.66; 'received:fios.verizon.net': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python's and and Pythons or Date: Thu, 10 Oct 2013 03:43:15 -0400 References: <91180c35-413f-4b65-a224-917d8d68b7ec@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 In-Reply-To: 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381391010 news.xs4all.nl 15930 [2001:888:2000:d::a6]:41912 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56553 On 10/10/2013 2:45 AM, Chris Angelico wrote: > On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi > wrote: >> I'm trying to think of a good example usage of echo-argument and. Maybe something like >> A bit awkward, echo-argument or is more naturally useful to me then echo-argument and. > > first_element = some_list[0] # Oops, may crash some_list[0:1] always works, and sometimes is usable, but you still cannot index the slice. > try: > first_element = some_list[0] > except IndexError: > firstelement = None # A bit verbose > > first_element = some_list and some_list[0] > > # or if you want a zero instead of an empty list: > first_element = len(some_list) and some_list[0] > > > Also, consider the case where you have a function, or None: > > result = func(*args,**kwargs) # NoneType is not callable > > result = func and func(*args,**kwargs) y = x and 1/x One just has to remember that y==0 effectively means y==+-infinity ;-). -- Terry Jan Reedy