2013年1月30日
摘要: array 1 package main 2 3 import "fmt" 4 5 func main() { 6 var arr [5]int 7 arr[0] = 52 8 arr[1] = 53 9 for i, v := range arr {10 fmt.Println(i, v)11 }12 //采用...的方式Go会自动根据元素个数来计算长度13 b := [...]int{1, 2, 3, 4, 5, 6}14 fmt.Println(len(b))15 //二维数组16 //也... 阅读全文
posted @ 2013-01-30 22:59 liubiaoren 阅读(139) 评论(0) 推荐(0)
摘要: if 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func computedValue() int { 8 return 8 9 }10 11 func main() {12 //if还有一个强大的地方就是条件判断语句里面允许声明一个变量,13 //这个变量的作用域只能在该条件逻辑块内,其他地方就不起作用了,如下所示14 // 计算获取值x,然后根据x返回的大小,判断是否大于10。15 if x := computedValue(); x > 10 {16 fmt.Println("... 阅读全文
posted @ 2013-01-30 21:12 liubiaoren 阅读(140) 评论(0) 推荐(0)
摘要: 运算符和内建函数优先级 高 * / % << >> & &^ + - | ^ == != < <= > >= <- && 低 ||& | ^ &^ 分別是运算符安位与,或,异或,清除逻辑非:!Go保留字break default func interface selectcase defer go map structchan else goto package switchconst fallthrough if ... 阅读全文
posted @ 2013-01-30 15:41 liubiaoren 阅读(114) 评论(0) 推荐(0)
摘要: 1.变量 1 package main 2 3 import "fmt" 4 5 //注意是()而不是{} 6 var ( 7 x int 8 b bool 9 )10 11 func main() {12 x = 12313 b = true14 fmt.Println(x, b)15 //变量名是下划线时,任何赋给它的值都被丢弃16 a, _ := 34, 3517 fmt.Println(a)18 }输出结果如下:123 true
34注意:变量声明了但未使用编译会报错。2.类型布尔类型bool:true或false数字... 阅读全文
posted @ 2013-01-30 11:33 liubiaoren 阅读(275) 评论(0) 推荐(0)
摘要: 1 package main 2 3 import "fmt" 4 5 func main() { 6 fmt.Printf("Hello,world or 你好,世界 or καλημ ?ρα κóσμ or こんにちは世界\n") 7 fmt.Print("Hello,word!") 8 //输出后换行 9 fmt.Println("Hello,word!")10 //可以格式化输出内容,字符%s,数字%d,浮点%f11 s := "我是字符"12 d := 12313 f := 阅读全文
posted @ 2013-01-30 10:49 liubiaoren 阅读(259) 评论(0) 推荐(0)