慕盖茨4494581
您可以使用:func format(s1, s2 []string) string { if reflect.DeepEqual(s1, s2) { return "%v\n" } return "%q\n"}像这个工作样本(The Go Playground):package mainimport ( "fmt" "reflect")func main() { s1, s2 := []string{"a", "b", "c"}, []string{"a b", "c"} frmat := format(s1, s2) fmt.Printf(frmat, s1) // ["a" "b" "c"] fmt.Printf(frmat, s2) // ["a b" "c"] s2 = []string{"a", "b", "c"} frmat = format(s1, s2) fmt.Printf(frmat, s1) // ["a" "b" "c"] fmt.Printf(frmat, s2) // ["a b" "c"]}func format(s1, s2 []string) string { if reflect.DeepEqual(s1, s2) { return "%v\n" } return "%q\n"}输出:["a" "b" "c"]["a b" "c"][a b c][a b c]