Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'string.': 0.05; 'element': 0.07; 'string': 0.09; 'cc:addr:python- list': 0.11; 'jan': 0.12; '"in"': 0.16; 'element.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'length.': 0.16; 'sliced': 0.16; 'used:': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'starts': 0.20; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'sean': 0.24; 'tells': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'mention': 0.26; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'context.': 0.31; 'another': 0.32; 'beginning': 0.33; 'position.': 0.33; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'found.': 0.36; 'method': 0.36; 'should': 0.36; 'list': 0.37; 'starting': 0.37; 'ends': 0.38; 'pm,': 0.38; 'does': 0.39; '2nd': 0.60; 'negative': 0.60; 'number,': 0.60; 'back': 0.62; 'more': 0.64; 'forward': 0.65; 'ending': 0.78; 'counts': 0.83; 'end.': 0.84; 'here!': 0.84; '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=2d3+2QJdNFP5w9NKoOKQhP8DCkJsEBJDfYNQ/4XYVZA=; b=Tha5CIbJOtNo8UcqbJ46Gmi5xgtWjmu5GtgSL9hD6C/OFP1eoIgxcwPOb2u9XBBTqS 1Sy8QMvzUnsAlkNAFNh0SOqkfbWFRqMHTlIKkgNHRwTUCaxxO/BAvebiyNfM4xpRgNDY RcAH8BHSYxPA+PblclhdxGSAAAl5giJOpAB+lAW9yGNoL7xdDuItmHnd55+kl7TL8Aj3 ZFl8WRVxeiQfWA16qrpX4NNKmPaDVv42M7+3aEIKrhtCSV3HHOJbo/kCYI2wOCmQyPX9 ZMhNudsLmIb26Jhnm0W/v6Rl8CydI9YxnS+NiFUNxkcMH7U0E6dOR1I0Uc3RyNXeAG86 5IDA== MIME-Version: 1.0 X-Received: by 10.68.244.103 with SMTP id xf7mr55799646pbc.50.1388821172840; Fri, 03 Jan 2014 23:39:32 -0800 (PST) In-Reply-To: <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> Date: Sat, 4 Jan 2014 18:39:32 +1100 Subject: Re: Strange behaviour with a for loop. 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388821182 news.xs4all.nl 2865 [2001:888:2000:d::a6]:39428 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63118 On Sat, Jan 4, 2014 at 5:32 PM, Sean Murphy wrote: > So I suspect the offset number still starts at the beginning of the string and counts forward or another way to look at it you are slicing from element x to element y. If element y is less then element x, return nothing. Does this make sense? > > I should have used: > > print a[4:6]) > > to get: > > t.t Yep, it's start and end indices, not start and length. When you use a negative number, it counts from the back: >>> "asdf"[-1] 'f' >>> "asdf"[-2] 'd' > The 2nd part of my original question still stands. I will expand upon this a bit more to give more context. I want to print from the beginning of the paragraph to the end. Each paragraph ends with "\n\n\n". > > If I use "\n\n\n" in lines this does return true for the string. But I don't have a starting position and ending position. The list method which I mention before can be sliced by going back one element. The "in" operator just tells you whether it's there or not; strings have a .index() method that tells you where something can be found. That might be what you want here! ChrisA