How to return multiple values from a function in Go and what to use instead of tuples?
Hello everyone! I just started learning Go after Python, and I have a problem. In Python, I often used tuples to, for example, return multiple values from a function at once or group a pair of related data. For example:
```python
def get_user():
return ("Alice", 30)
name, age = get_user()
```
But in Go, I can't find a built-in "tuple" or "pair" type. The documentation says that a function can return multiple values, but it's not quite the same thing. When I try to do something similar:
```go
func getUser() (string, int) {
return "Alice", 30
}
func main() {
name, age := getUser()
fmt.Println(name, age) // This works
}
```
Everything is fine as long as I just want to unpack the result into variables. But what if I want to save the resul
No answers yet.
Log in to leave an answer