当前位置:网站首页>Go语言自学系列 | go语言数据类型
Go语言自学系列 | go语言数据类型
2022-07-01 18:36:00 【51CTO】
视频来源:B站《golang入门到项目实战 [2021最新Go语言教程,没有废话,纯干货!持续更新中...]》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
在 Go 编程语言中,数据类型用于声明函数和变量。
数据类型的出现是为了把数据分成所需内存大小不同的数据,编程的时候需要用大数据的时候才需要申请大内存,就可以充分利用内存。
Go 语言按类别有以下几种数据类型:
序号 | 类型和描述 |
1 | 布尔型 布尔型的值只可以是常量 true 或者 false。一个简单的例子:var b bool = true。 |
2 | 数字类型 整型 int 和浮点型 float32、float64,Go 语言支持整型和浮点型数字,并且支持复数,其中位的运算采用补码。 |
3 | 字符串类型: 字符串就是一串固定长度的字符连接起来的字符序列。Go 的字符串是由单个字节连接起来的。Go 语言的字符串的字节使用 UTF-8 编码标识 Unicode 文本。 |
4 | 派生类型: 包括:(a) 指针类型(Pointer)(b) 数组类型 (c) 结构化类型(struct)(d) Channel 类型 (e) 函数类型 (f) 切片类型 (g) 接口类型(interface)(h) Map 类型 |
数字类型
Go 也有基于架构的类型,例如:int、uint 和 uintptr。
序号 | 类型和描述 |
1 | uint8 无符号 8 位整型 (0 到 255) |
2 | uint16 无符号 16 位整型 (0 到 65535) |
3 | uint32 无符号 32 位整型 (0 到 4294967295) |
4 | uint64 无符号 64 位整型 (0 到 18446744073709551615) |
5 | int8 有符号 8 位整型 (-128 到 127) |
6 | int16 有符号 16 位整型 (-32768 到 32767) |
7 | int32 有符号 32 位整型 (-2147483648 到 2147483647) |
8 | int64 有符号 64 位整型 (-9223372036854775808 到 9223372036854775807) |
浮点型
序号 | 类型和描述 |
1 | float32 IEEE-754 32位浮点型数 |
2 | float64 IEEE-754 64位浮点型数 |
3 | complex64 32 位实数和虚数 |
4 | complex128 64 位实数和虚数 |
其他数字类型
以下列出了其他更多的数字类型:
序号 | 类型和描述 |
1 | byte 类似 uint8 |
2 | rune 类似 int32 |
3 | uint 32 或 64 位 |
4 | int 与 uint 一样大小 |
5 | uintptr 无符号整型,用于存放一个指针 |
举例
package main
import "fmt"
func a3() {
}
func main() {
var name string = "tom"
age := 20
b := true
fmt.Printf("name: %T\n", name)
fmt.Printf("age: %T\n", age)
fmt.Printf("b: %T\n", b)
a := 100
p := &a
fmt.Printf("p: %T\n", p)
a1 := [2]int{1, 2}
fmt.Printf("a1: %T\n", a1)
a2 := []int{1, 2, 3}
fmt.Printf("a2: %T\n", a2)
fmt.Printf("a3: %T\n", a3)
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
运行结果
边栏推荐
- Single element of an ordered array
- 研究了11种实时聊天软件,我发现都具备这些功能…
- R语言ggplot2可视化:可视化折线图、使用labs函数为折线图添加自定义的Y轴标签信息(customize y axis label)
- R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
- 隐私沙盒终于要来了
- Static timing analysis (STA) in ic/fpga design
- Go Technology Daily (2022-02-14) - go language slice interview real questions 8 consecutive questions
- Navicat Premium 15 永久破解和2021版本最新IDEA破解(亲测有效)
- Implementation of converting PCM file to WAV
- C# SelfHost WebAPI (2)
猜你喜欢

磁盘的基本知识和基本命令

Computer network interview assault

Cloud computing - make learning easier

A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database

12种数据量纲化处理方式

540. Single element in ordered array / 1684 Count the number of consistent strings

How does factor analysis calculate weights?

实现一个Prometheus exporter

The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup

MySQL connection tools
随机推荐
Basic concepts of binary tree
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
Is Alipay wallet convenient to use?
[CF1476F]Lanterns
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses PCH parameters to customize the shape o
Leetcode203 移除链表元素
Classpath classpath
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷
C language learning notes: type definition typedef and declaration external CSDN creation punch in
C operator overloads the query table
Calculation of intersection of two line segments
Halcon image calibration enables subsequent image processing to become the same as the template image
How to manage 1000 anchors by one person?
OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习
R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
信度系数低怎么办?信度系数具体怎么算?
Three.js学习-相机Camera的基本操作(了解向)