如何正确定义一个函数? [英] How to correctly define a function?
本文介绍了如何正确定义一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
count_letters(word)= count_vowels(word )+ count_consonants(word)
但由于某种原因,这是错误的。我得到这个错误:
$ b
SyntaxError:无法赋值给函数调用
我该如何解决它?
谢谢
解决方案
这不是您在python中声明函数的方法。你要写的是:
pre $ def count_letters(word):
return count_vowels(word)+ count_consonants(word )
也就是说,如果您已经有 count_vowels
和 count_consonants
函数。
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
解决方案
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.
这篇关于如何正确定义一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文