Created
February 5, 2015 17:25
-
-
Save giwa/03e007b3714f03532475 to your computer and use it in GitHub Desktop.
Go by Examples: Multiple Return Values ref: http://qiita.com/giwa@github/items/2789d0ddf86bffb37f9f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
//この関数において(int, int)はこの関数は2つのintを返すことを示します。 | |
func vals() (int, int) { | |
return 3, 7 | |
} | |
func main() { | |
// ここでは、複数に代入する関数の呼び方から2つの違った値を受け取ります。 | |
a, b := vals() | |
fmt.Println(a) | |
fmt.Println(b) | |
// もし返り値の一部を使いたい場合は、_を使ってください。 | |
_, c := vals() | |
fmt.Println(c) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run multiple-return-values.go | |
3 | |
7 | |
7 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment