[Tutor] really basic - finding multiline chunk within larger chunk
__peter__ at web.de
Tue Feb 16 14:10:49 EST 2016
> I've got a test, where I have a chunk of text "a" and a subset of text
> "s2a". the subset is multiline.
> For some reason, can't seem to return true on the find. I've pasted in
> http://fpaste.org/323521/, but the following is an example as well.
> (not sure if the psuedo code listed actually shows the chunks of text
> with the whitespace correctly.
> Obviously, this is an "example" not meant to be real code!!
> Thoughts on what I've screwed up?
str.find() returns -1 when the substring is not found. Other return values
including 0 mean that the substring was found -- the return value is the
start index of the substring in the larger string:
>>> "foo bar".find("bar")
>>> "foo bar".find("foo")
>>> "foo bar".find("baz")
If you only want to know if the substring occurs and do not need the start
index the clearest test uses the in operator:
>>> "foo" in "foo bar"
More information about the Tutor