Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'mrab': 0.04; 'character,': 0.07; 'python': 0.08; 'between.': 0.09; 'identifies': 0.09; 'subject:method': 0.09; 'am,': 0.12; "subject:' ": 0.15; '(eg': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Bizarre': 0.16; 'subject:behavior': 0.16; 'subject:find': 0.16; 'wrote:': 0.16; 'string,': 0.18; 'header:In-Reply-To:1': 0.22; 'end,': 0.23; 'slice': 0.23; 'aug': 0.24; 'index': 0.24; 'string': 0.26; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.29; 'characters,': 0.30; 'chris': 0.32; 'agree': 0.33; 'it.': 0.33; 'to:addr:python-list': 0.33; 'character': 0.34; 'rather': 0.35; 'uses': 0.35; 'beginning': 0.36; 'could': 0.38; 'think': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'characters': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'alternative': 0.64; 'positions': 0.65; 'bible': 0.67; '11,': 0.68; 'wish': 0.69; 'inclusive': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=aK4by5RZU0710KCVvhOtAR1pnyDwABcEGUpsXVcG0EY=; b=F7aCDTFyBTGouAJjvbxuIwfzOIVuhgibdgtP/kpphjOhX4HwVfHGPSn+cw/v1dhohY Ljg+EzB3ghppJwuOgWVLx8rU8ER3XS4K4jhEdKvRkvskrC4Q+jhBOfaQAzarcCSYa1Nt YKscMP5SqfHPEk4+JnKVrGLcyILu/E41eqziU= MIME-Version: 1.0 In-Reply-To: <4E4334F3.5000005@mrabarnett.plus.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4E4334F3.5000005@mrabarnett.plus.com> Date: Thu, 11 Aug 2011 03:14:30 +0100 Subject: Re: Bizarre behavior of the 'find' method of strings From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313028873 news.xs4all.nl 23908 [2001:888:2000:d::a6]:46328 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11167 On Thu, Aug 11, 2011 at 2:48 AM, MRAB wrote: > Python uses half-open ranges, which means that the start position is > inclusive and the end position is exclusive. > Or if you prefer: Python identifies positions between characters, rather than characters. And I agree that it's better than the alternative - in fact, I wish other systems could work the same way (eg Bible references). If you think about position 0 being the very beginning of the string, and position len(s) being the very end, then you slice the string from position to position and take the characters between. When you index the string for a particular character, you aim at a position and take the character after it. Chris Angelico