bool类型

package main

import (
"fmt"
)

func main() {
/* var a bool = true
var b = false
c := true
fmt.Printf("a: %v\n", a)
fmt.Printf("b: %v\n", b)
fmt.Printf("c: %v\n", c) */

//在判断中
/* age := 18
if age >= 18 {
fmt.Println("成年")
} else {
fmt.Println("未成年")
} */

/* age := 16
b := age >= 18
fmt.Printf("b: %v\n", b) //输出false
if b {
fmt.Println("成年")
} else {
fmt.Println("未成年")
} */

/* count := 10
for i := 0; i < count; i++ {
fmt.Printf("i=%v\n", i)
} */

age, gender := 18, "男"
if age >= 18 && gender == "男" {
fmt.Println("成年男")
}
}

数字类型

有符号int8

无符号uint8

十进制:输出时用%d

二进制:输出时用%b

八进制:定义数字时用0开头,输出%x

十六进制:定义数字时用0x开头,输出时用%X

浮点数:输出用%f

import (
"fmt"
"math"
"unsafe"
)

func main() {
var i8 int8
fmt.Println("%T,%dB %v~%v", i8, math.MinInt8)
}

字符串

package main

import (
"fmt"
"strings"
)

func main() {
/* s1 := "hello"
s2 := `
ni
hao
a
`
// s3 := s1 + s2
s3 := strings.Join([]string{s1, s2}, ",")
fmt.Printf("s1: %v\n", s1)
fmt.Printf("s2: %v\n", s2)
fmt.Printf("s3: %v\n", s3) */

/* 转义字符
\n 回车
\t tab键
\\ 转义\ */

//切片
s := "hello world"
fmt.Printf("s[1]: %c\n", s[1])
fmt.Printf("s[4:]: %v\n", s[4:])

//字符串长度
fmt.Printf("len(s): %v\n", len(s))
//转换为数组
s1 := strings.Split(s, "")
fmt.Printf("s1: %v\n", s1)
//是否包含
fmt.Printf("strings.Contains(s, \"hello\"): %v\n", strings.Contains(s, "hello"))
}