如何解决Golang中“返回的参数过多”的问题?
在我正在写的打印函数中,我试图根据switch语句的结果返回一个值;但是,我得到的错误太多,无法返回。
如果这个问题的答案很简单,请原谅我,但是函数有多少个参数可以返回一件事就不应该吗?还是需要为每个参数返回一件事。
这是我的代码。我在返回行上收到错误(返回的参数过多)。如何修复它,使其返回在switch语句中设置的字符串?
package bayfunc Print(DATA []TD, include string, exclude []string, str string) {
result := NBC(DATA, include, exclude, str)
var sentAnal string
switch result {
case 1:
sentAnal = "Strongly Negative"
case 2:
sentAnal = "Very Negative"
case 3:
sentAnal = "Negative"
case 4:
sentAnal = "Little Negative"
case 5:
sentAnal = "Neurtral"
case 6:
sentAnal = "Little Positive"
case 7:
sentAnal = "Positive"
case 8:
sentAnal = "More Positive"
case 9:
sentAnal = "Very Positive"
case 10:
sentAnal = "Strongly Positive"
default:
sentAnal = "Unknown"
}
return sentAnal
}
回答:
您需要指定输入参数后返回的内容,这不是python。
这个:
func Print(DATA []TD, include string, exclude []string, str string) {
应该:
func Print(DATA []TD, include string, exclude []string, str string) string {
推荐读物:
http://golang.org/doc/effective_go.html#multiple-returns
http://golang.org/doc/effective_go.html#named-results
甚至全部有效
以上是 如何解决Golang中“返回的参数过多”的问题? 的全部内容, 来源链接: utcz.com/qa/418129.html