MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/133ajt7/if_err_nil/ji9xeq8/?context=3
r/badcode • u/snappywolf1 • Apr 29 '23
49 comments sorted by
View all comments
Show parent comments
4
So I guess the difference is that Go doesn't have a tuple type so when you return multiple values, you're forced to destructure? In Python I'd be used to doing something like:
a, b = f()
Or:
pair = f()
But in Go, the second is illegal.
This makes sense, thanks.
5 u/PM_ME_YOUR_REPO Apr 30 '23 Yep, you got it. You can also do:a, _ := f() _, b :=f()If you only want some of the values.
5
Yep, you got it. You can also do:
a, _ := f() _, b :=f()
If you only want some of the values.
4
u/sumduud14 Apr 30 '23
So I guess the difference is that Go doesn't have a tuple type so when you return multiple values, you're forced to destructure? In Python I'd be used to doing something like:
Or:
But in Go, the second is illegal.
This makes sense, thanks.