#undocumented examples from class import string str1 = "hello there class" str2 = "here" #begin option 1 if str2 in str1: print "String: ", str1, " contains String: ", str2 else: print "String: ", str1, " does not contain String: ", str2 #end option 1 #begin option 2 index = string.find(str1, str2) if index != -1: print "String: ", str1, " contains String: ", str2, " starting at position ", index else: print "String: ", str1, " does not contain String: ", str2 #end option 2 #begin option 3 x = 0 while x < (len(str1)-len(str2)+1): tocomp = str1[x:(x+len(str2))] print tocomp if str2 == tocomp: print "String ", str1, " contains String: ", str2, " starting at position ", x x += 1 #end option 3 #mystring = "CS is cool" #print mystring #mystring = mystring[:len(mystring)-1] #print mystring #print mystring[4:18] #mystring = "the" #length = len(mystring) #target = "z" #found = False #target not found in string #index = 0 #while index < len(mystring): # if mystring[index] == target: # print "The string ", mystring, " contains the character ", target # found = True # index += 1 #if found == False: #if the character was not found # print "The character does not appear in the string" #print "The length of the string ", mystring, " is ", length #last = mystring[length-1] #print "The last char is ", last