On Fri, 10 Dec 2010, Alan Gauld wrote:

"Ben Ganzfried" <[email protected]> wrote

 n = s.find('not')
 b = s.find('bad')
 if n != -1 and b != -1 and b > n:
   s = s[:n] + 'good' + s[b+3:]
 return s

It's clear that n!=-1 and b!=-1 means something like : "if in the
string 's' we find the word "not" and in string 's' we find the word
"bad."

Exactly the oopsite in fact.
find() returns the index where the string is fouind.
-1 means the string was not found

I don't think it's opposite; I think Ben and Alan are saying the same thing, albeit in different ways.

Ben:

  n = s.find('not')
  n!=-1 ... means something like : "if in the string 's' we find the word
   "not"

Yes; "n != -1" means "not not found", that is, found.

(ditto for the discussion of "b!=-1")

Alan:
  -1 means the string was not found

Exactly. Both of you are saying that -1 means "not found"; Ben is expresing that negating that is equivalent to "found."
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to