Search code examples
pythonfunctiondefinition

How to correctly define a function?


In python I'm trying to do the following to define a function:

count_letters(word) = count_vowels(word) + count_consonants(word)

But for some reason, it is wrong. I'm getting this error:

SyntaxError: can't assign to function call

How can I fix it?

Thank you


Solution

  • This is not how you declare a function in python. What you want to write is:

    def count_letters(word):
        return count_vowels(word) + count_consonants(word)
    

    That is if you already have a count_vowels and a count_consonants function.