Go multiple return values¶
In Go, functions are not limited to returning a single value. Instead, they can return multiple outputs simultaneously^[400-devops-09-scripting-language-golang-introduction-readme.md].
This feature is useful when a function needs to return more than one piece of data to the caller^[400-devops-09-scripting-language-golang-introduction-readme.md]. For example, when working with data types, one might need to return a list of customers alongside the list of cities they are from^[400-devops-09-scripting-language-golang-introduction-readme.md].
Syntax¶
The syntax for returning multiple values involves listing the return types in parentheses within the function signature^[400-devops-09-scripting-language-golang-introduction-readme.md].
func getData(inputs)(outputs){
// functions can take multiple inputs, and return multiple outputs
}
Related Concepts¶
- [[Go functions]]
- [[Go structs]]
- [[Go slices]]
Sources¶
^[400-devops-09-scripting-language-golang-introduction-readme.md]