Introduction
Sometimes a function needs to give back more than one piece of information. Multiple return values let a function send back several results at once.
func functionName() (type1, type2) {
// code
return value1, value2
}func divide(a, b int) (int, int) { return a / b, a % b }
func getName() (string, string) {
return "John", "Doe"
}func status() (bool, string) {
return true, "Success"
}package main import "fmt" func divide(a, b int) (int, int) { return a / b, a % b } func main() { quotient, remainder := divide(10, 3) fmt.Printf("Quotient: %d, Remainder: %d\n", quotient, remainder) }
package main
import "fmt"
func divide(a, b int) (int, int) {
return a / b, a % b
}
func main() {
q, r := divide(10, 3)
fmt.Println(q, r)
}func names() (string, string) {
return "Alice"
}Pass the test and this pattern moves unknown