Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63118
| References | <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> <la86n0$sdk$1@ger.gmane.org> <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> |
|---|---|
| Date | 2014-01-04 18:39 +1100 |
| Subject | Re: Strange behaviour with a for loop. |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4898.1388821182.18130.python-list@python.org> (permalink) |
On Sat, Jan 4, 2014 at 5:32 PM, Sean Murphy <mhysnm1964@gmail.com> 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Strange behaviour with a for loop. Chris Angelico <rosuav@gmail.com> - 2014-01-04 18:39 +1100
csiph-web