Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!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; 'python': 0.08; '>>>>': 0.09; 'folks,': 0.09; 'from:addr:python': 0.09; 'subject:method': 0.09; "subject:' ": 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'subject:Bizarre': 0.16; 'subject:behavior': 0.16; 'subject:find': 0.16; 'wrote:': 0.16; 'language': 0.17; 'programming': 0.20; 'this?': 0.21; 'header:In-Reply-To:1': 0.22; 'extending': 0.23; 'string': 0.26; 'received:84': 0.28; 'fewer': 0.30; "can't": 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'reply- to:addr:python.org': 0.34; 'uses': 0.35; 'thank': 0.35; '(with': 0.35; 'starting': 0.36; 'jim': 0.37; 'using': 0.37; 'but': 0.37; 'something': 0.37; 'think': 0.38; 'subject:: ': 0.39; 'help': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'results': 0.61; 'here': 0.65; 'greetings,': 0.66; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'inclusive': 0.84; 'ranges': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiQGAPYzQ05UXebj/2dsb2JhbABBmDqPBneBQAEBBThAEQsIEAkUAg8JAwIBAgFFEwgBAYdsvQuGRgSYFItk Date: Thu, 11 Aug 2011 02:48:35 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Bizarre behavior of the 'find' method of strings References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> In-Reply-To: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 1313027314 news.xs4all.nl 23952 [2001:888:2000:d::a6]:51963 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11166 On 11/08/2011 02:24, Jim wrote: > Greetings, folks, > > I am using python 2.7.2. Here is something I got: >>>> a = 'popular' >>>> i = a.find('o') >>>> j = a.find('a') >>>> a[i:j] > 'opul' > > Well, I expected a[i:j] to be 'opula', and can't think of any reason > why this is not happening. So, can anybody help me out about this? > Thank you very much. > Python uses half-open ranges, which means that the start position is inclusive and the end position is exclusive. This means that a[i:j] returns the string starting at position i and extending upto, but excluding, position j. The reason that Python uses half-open ranges is that experience (with the language Mesa) has shown that it results in fewer programming errors that the alternatives.