[Tutor] string indexing
rahmad akbar
matbioinfo at gmail.com
Sun Jan 19 14:59:32 CET 2014
hey guys, super noob here, i am trying to understand the following code
from google tutorial which i failed to comprehend
#code start
# E. not_bad
# Given a string, find the first appearance of the
# substring 'not' and 'bad'. If the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# Return the resulting string.
# So 'This dinner is not that bad!' yields:
# This dinner is good!
def not_bad(s):
# +++your code here+++
# LAB(begin solution)
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
#code end
on the following lines, what is -1, is that index number? and i dont
understand the entire second line
if n != -1 and b != -1 and b > n:
s = s[:n] + 'good' + s[b+3:]
--
many thanks
mat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140119/7ee0a904/attachment-0001.html>
More information about the Tutor
mailing list