Article start exercise
Style

Python has a style guide called PEP8 which is definitly worth a read.

A few things can be improved :


function name does not respect convention
missing whitespaces
useless parenthesis
name str hides builtin str


Then your code becomes :

def starts_with_article(string):
    '''Return True if the first word of string is "The", "A" or "An"'''

    if string.startswith("The ") and string.find(' ') == 3:
        return True
    elif string.startswith("An ") and string.find(' ') == 2:
        return True
    elif string.startswith("A ") and string.find(' ') == 1:
        return True

    return False

print('"A boy" returned', starts_with_article("A boy"))
print('"An apple" returned', starts_with_article("An apple"))
print('"The cat" returned', starts_with_article("The cat"))
print('"Abyss" returned', starts_with_article("Abyss"))
print('"There" returned', starts_with_article("There"))
print('"Ant" returned', starts_with_article("Ant"))


Don't Repeat Yourself

You are doing the same thing multiple times. You could try to see what is similar and what changes and see if you can use a relevant data structures for the changing parts.

Here I stored the articles in a list to be able to iterate over them.

def starts_with_article(string):
    '''Return True if the first word of string is "The", "A" or "An"'''
    for article in ["The ", "An ", "A "]:
        if string.startswith(article) and string.find(' ') == len(article) - 1:
            return True

    return False


Don't repeat yourself (again)

You are looking for the article followed by a space and then you check if there is a space in the wanted position. There is no need for that check.

def starts_with_article(string):
    '''Return True if the first word of string is "The", "A" or "An"'''
    for article in ["The ", "An ", "A "]:
        if string.startswith(article):
            return True

    return False


Don't repeat yourself (again again)

I have to repeat the whitespace in the different elements of the list I a using. This is easy to forget if I ever need to add an article. Let's add the space as part of the logic.

def starts_with_article(string):
    '''Return True if the first word of string is "The", "A" or "An"'''
    for article in ["The", "An", "A"]:
        if string.startswith(article + ' '):
            return True
    return False


More Python good stuff

The any builtin seems to do what you are doing. Let's use it.

def starts_with_article(string):
    '''Return True if the first word of string is "The", "A" or "An"'''
    return any(string.startswith(article + ' ')
        for article in ["The", "An", "A"])


The best option: reading the documentation

If we look at the startswith documentation, we have:


  prefix can also be a tuple of prefixes to look for.


At that point, your problem is pretty much solved :-)