Go语言是静态类型语言,并且不具备低精度向高精度自动转换功能,所以不同类型变量之间相互赋值需要进行类型转换.
func main() { //声明3个类型变量 var a int = 1 var b int32 = 2 var c int64 = 3 fmt.Println(a, b, c) //把int32转换为int64 a = int(b) fmt.Println(a, b) a = 1 //把int64转换成int32 b = int32(c) fmt.Println(b, c) b = 2 //把int转换为int64 c = int64(a) fmt.Println(a, c) c = 3 }