一尘不染

如何解决Golang中“返回的参数过多”的问题?

go

在我正在写的打印函数中,我试图根据switch语句的结果返回一个值;但是,我得到的错误太多,无法返回。

如果这个问题的答案很简单,请原谅我,但是函数有多少个参数可以返回一件事就不应该吗?还是需要为每个参数返回一件事。

这是我的代码。我在返回行上收到错误(返回的参数过多)。如何修复它,使其返回在switch语句中设置的字符串?

package bay

func 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
}

阅读 673

收藏
2020-07-02

共1个答案

一尘不染

您需要指定输入参数后返回的内容,这不是python。

这个:

func Print(DATA []TD, include string, exclude []string, str string) {

应该:

func Print(DATA []TD, include string, exclude []string, str string) string {

推荐读物:

甚至全部有效

2020-07-02