当前位置:网站首页>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.
运行结果
边栏推荐
- Calculation of intersection of two line segments
- 必看,时间序列分析
- Find all missing numbers in the array
- 宏观视角看抖音全生态
- 搭建一个通用监控告警平台,架构上需要有哪些设计
- Principal component calculation weight
- Memo - about C # generating barcode for goods
- R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
- Mysql database design
- Computer network interview assault
猜你喜欢
Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
LiveData postValue会“丢”数据
Leetcode-160相交链表
关于企业中台规划和 IT 架构微服务转型
About enterprise middle office planning and it architecture microservice transformation
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
Operation of cmake under win
搭建一个通用监控告警平台,架构上需要有哪些设计
12. Design of power divider for ads usage record
随机推荐
Vidéos courtes recommandées chaque semaine: méfiez - vous de la confusion entre « phénomène » et « problème »
Basic knowledge and commands of disk
Classpath classpath
PCL learning materials
R language ggplot2 visualization: gganimate creates a dynamic histogram animation (GIF), and displays the histogram and enter step by step along a given dimension in the animation_ Growth function and
12. Design of power divider for ads usage record
[acnoi2022] color ball
Halcon image calibration enables subsequent image processing to become the same as the template image
R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
Unity learning fourth week
Basic concepts of binary tree
Data query language (DQL)
2020,最新手机号码手机验证正则表达式,持续更新
Technology implementation and Architecture Practice
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
R语言使用dplyr包的transmute函数计算dataframe数据中的指定数据列的移动窗口均值、使用ggplot2包可视化移动均值与原始数据的折线图
The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
How to find the optimal learning rate
C operator overloads the query table
力扣每日一题-第32天-589.N×树的前序遍历