Write the function search(word, substring) that takes in a word and a substring as arguments and returns the position (0 indexed) of the substring if it is found in the word. The function returns -1 if the substring is not found.

is there a method to do this? i tried;

def search(word, substring):
    if substring in word:
        return 1
        return -1

but on one of their tests it returned false, because i misunderstood the question i imagine. so how should i go about this problem?

thank you for any help~

There is built in find method, which I think you should implement yourself as exercise. Use loop to check for every possible starting place. Initialize the result variable to -1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.