Created
April 24, 2017 16:49
-
-
Save modeverv/b25942c56f1c9290fb3757eb77cbe78a to your computer and use it in GitHub Desktop.
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" | |
"time" | |
"math" | |
) | |
// Contants | |
const oPi = "おっぱい" | |
// セミコロンはいらないんじゃ | |
func main() { | |
fmt.Println("bbbbbb") | |
fmt.Println("aaaaa") | |
fmt.Println("The time is" , time.Now()) | |
fmt.Println(math.Sqrt(7)) | |
fmt.Println(math.Pi) | |
fmt.Println(add(42,33)) | |
a, b := swap("world", "Hello") | |
fmt.Println(a, b) | |
fmt.Println(split(17)) | |
var x int | |
x = 10 | |
fmt.Println(x) | |
// variable with initializers | |
var i,j int = 1, 2 | |
//var c, python, java = true, false, "no!" // 型推論ついてる? | |
fmt.Println(i,j,c,python,java) | |
// short variable declarations | |
k := 3 | |
c,python,java := true, false, "no!" // まごうことなき型推論 | |
fmt.Println(i,j,k,c,python,java) | |
// C言語とは異なり、Goでの型変換は明示的な変換が必要です。 | |
} | |
/** | |
* Go docとかはないのでしょうか | |
* func 関数名(変数 型 ) 戻り型 { 処理 } | |
*/ | |
func add(x int,y int) int { | |
return x + y | |
} | |
func add2(x ,y int) int { | |
return x + y | |
} | |
// multipule results | |
func swap(x,y string) (string, string) { | |
return y,x | |
} | |
// named return values | |
func split(sum int) (x,y int) { | |
x = sum * 4 / 9 | |
y = sum - x | |
return | |
} | |
// variables | |
var c, python, java bool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment