觀看B站李文周老師的視頻學習golang整理的筆記
變數
var 變數名 變數型別
var(
a int
b int
)
a := 10
a,_,c := 1,2,3
//其中2將不會被賦值
type 別名 型別
//type cjp int32 需要再main函式外面為型別定義別名
常亮
const 常量名 = 值
const{
a = 10
b = 20
}
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
從鍵盤獲取值
fmt.Scan(&a)
條件陳述句
-
switch陳述句【 switch默認相當于每個case最后帶有break,匹配成功后不會自動向下執行其他case,而是跳出整個switch, 但是可以使用fallthrough強制執行后面的case代碼,fallthrough不會判斷下一條case的expr結果是否為true】
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")
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/264368.html
標籤:Go
上一篇:學了那么久,你還不懂指標嗎?帶你看看別人是怎么把指標按在地上摩擦
下一篇:Go | Go 結合 Consul 實作動態反向代理