数字转字符串,字符串转数字

package mainimport ( "fmt" "strconv")func main() { // 80 转换成 "80" //number := 80 // //number_int :=strconv.Itoa(number) // //fmt.Println(number_int) //fmt.Printf("%T", number_int) // 如果不用这种的,可能转出来的不是你想象中的那样 //number := 80 // //number_str := string(number) // //fmt.Println(number_str) // number_str = P, 对应到了相应的ascci码上了 //fmt.Printf("%T", number_int) // 字符串转数字 "80" 转换成 80 number := "80rrrrr" number_int, error := strconv.Atoi(number) if error == nil { fmt.Println("转换成功",number_int) }else { fmt.Println("转换错误,",error) } //fmt.Println(error) //fmt.Println(number_int) //fmt.Printf("%T", number_int)}iota 枚举

package mainimport "fmt"func main() { // 1 iota 常量×××, 每隔一行,自动累加1 // 2 iota 给常量赋值使用 const ( a = iota //0 b = iota // 1 c = iota // 2 ) fmt.Println(a,b,c) // 0 1 2 // 3 iota遇到const, 重置为0 const d = iota fmt.Println(d) // 4 可以只写一个iota const ( a1 = iota b1 c1 ) fmt.Println(a1, b1, c1) // 5 如果是同一行, 值都一样 const ( i = iota j1, j2, j3 = iota, iota, iota k = iota ) fmt.Println(i,"\t",j1,j2,j3, "\t",k)}