基本数据类型及转换
代码
package test
import "fmt"
func BasicDataTypes() {
fmt.Println("整数类型")
var (
n1 = 0b0101
n2 int8 = 0o77
n3 uint16 = 0xAF
)
fmt.Printf("n1=%v,type is %T\n", n1, n1)
fmt.Printf("n2=%v,type is %T\n", n2, n2)
fmt.Printf("n3=%v,type is %T\n", n3, n3)
fmt.Println("浮点类型")
var (
f1 = 1.0
f2 float32 = 1
f3 float64 = 2
)
fmt.Printf("f1=%v,type is %T\n", f1, f1)
fmt.Printf("f2=%v,type is %T\n", f2, f2)
fmt.Printf("f3=%v,type is %T\n", f3, f3)
fmt.Println("类型转换")
n2 = int8(n3)
fmt.Printf("n2=%v\n", n2)
fmt.Println("字符型")
var (
c1 byte
c2 = '0'
c3 rune = '中'
)
fmt.Printf("c1的码值=%v,码值对应的字符%c,type is %T\n", c1, c1, c1)
fmt.Printf("c2的码值=%v,码值对应的字符%c,type is %T\n", c2, c2, c2)
fmt.Printf("c3的码值=%v,码值对应的字符%c,type is %T\n", c3, c3, c3)
fmt.Println("布尔型")
var bool1 bool = true
fmt.Printf("bool1=%v,type is %T\n", bool1, bool1)
fmt.Println("字符串")
var s1 string = "hello"
fmt.Println(s1 + " world")
fmt.Println(s1, "world")
fmt.Println(len("XIXIXI"))
}
package main
import (
"GoExample/test"
)
func main() {
test.BasicDataTypes()
}
本博客参考自:
https://www.bilibili.com/video/BV1s341147US/?spm_id_from=333.337.search-card.all.click&vd_source=a642bb3ddc5b706845426dc41d73fbda
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现