观看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")
}