""" Purpose: demonstrate string method find(). """ # Initialize strings s = "can anyone" t = "an" # Find occurrences i1 = s.find( t ) i2 = s.find( t, i1 + 1 ) # start looking for next occurrence right after i3 = s.find( t, i2 + 1 ) # where the previous occurrence started # find() is a string method - this function belongs to all strings # string_youre_looking_in.find(string_youre_looking_for, starting_index) # the second input to find() is NOT looking for that number occurrence, it starts looking # at that index in the string/sequence # this will not work with numbers, but % (a multiple of 10) will give you digits in numbers # Print results print( "s:", s ) print( " ==========" ) print( " 0123456789 <== indices into s" ) print() print( "t:", t ) print() print( "s.find( t ):", i1 ) print( "s.find( t,", i1, "+ 1 ):", i2 ) print( "s.find( t,", i2, "+ 1 ):", i3 )