整形
类型转换举例
var ia int64 = 54345
var ib int32
ib = int32(ia)
fmt.Println("ibis", ib)
浮点形
go语言定义了两个浮点型
float32 等价于C语言的float类型,
float64 等价于C语言的double类型
float64 等价于C语言的double类型
浮点数的比较 math.Fdim(f1, f2) < p p为定义的精度 如 0.00000001
字符串
var str1 string
str1 = "this is first string"
str2 := "this is second string"
str3 := str1 + str2
fmt.Printf("the string str3: %s \n len: %d \n first char is %c \n", str3, len(str3), str3[0])
字符串可以用常规方法for循环遍历,应用len取的字符串长度,用str3[i]取值,依据下标取字符串中的字符,类型为byte,这里用另一种方法遍历:
for i, c