觀看B站李文周老師的視頻學習golang整理的筆記
變量
a,_,c := 1,2,3
//其中2將不會被賦值
type 別名 類型
//type cjp int32 須要再main函數外面爲類型定義別名
常亮
const{
a = iota // a = 0
b = iota // b = 1
}
//當 iota 遇到const時 被重置爲0
const a = iota //a = 0
const b = iota //b = 0
字符串
str := "hello world"
fmt.printf("str length is %d" , len(str)) //str length is 11
str := "hello world"
fmt.printf("str[0] is %c",str[0]) //str[0] is h
從鍵盤獲取值
條件語句
var a int = 2
switch {
case a == 2:
fmt.Print("aaaaaa")
fallthrough
case a < 1:
fmt.Print("bbbbbb")
fallthrough
case a == 3:
fmt.Print("cccccc")
}
//輸出 aaaaaabbbbbbcccccc
for i := 10; i < 20; i++ {
fmt.Print("asdasa")
}
//使用range關鍵字
str := "hello world"
for k, v := range str {
fmt.Printf("str[%d] is %c \n", k, v)
}
if a := 10;a < 20{
fmt.Println("a的值小於20")
}