Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63118 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-01-04 18:39 +1100 |
| Last post | 2014-01-04 18:39 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Strange behaviour with a for loop. Chris Angelico <rosuav@gmail.com> - 2014-01-04 18:39 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-01-04 18:39 +1100 |
| Subject | Re: Strange behaviour with a for loop. |
| Message-ID | <mailman.4898.1388821182.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web