[scode type="blue"]导言[/scode] 本人学过多门语言,如:JavaScript,Java,python,Golang,Kotlin等语言,以及其他小众语言。 学了越来越多的语言,最后发现语言的结果都是殊途同归的,关键字,标识符,基本类型都是围绕着已经规范了的点进行开发。 所以在这里将语言的各个情况做一个总结和规划。 希望他人看见这篇文章能够更好的学习编程语言。 本人英语并不是很好,所以有可能翻译部分数据和说法有着问题,欢迎大家讨论。 **大多数理论需要从代码方面来说,这里采用Go的代码来阐述,无论如何都是殊途同归的。** 之所以用Go是因为Go这门语言可以称之为新现代化的语言,而我个人对Go的理解勉强还行,所以从我的角度来讲就用他来说明了。 *更重要的是Go的话更容易翻看定义的源码* 因为我对于知识的理解和不断内容更新,可能文章会更新多次,文章末尾都有着更新日志。 --- ## 第一节 类型 首先这里要从操作系统的发展历史来说: 类型主要看编程语言是**强类型,弱类型**,为**OOP面向对象** ,**POP面向过程** ,**SOA面向服务** ,**AOP面向切面**,**解释型,编译型** 等。 *Go是一个编译型,更加面向过程的语言。* 这里贴入Go定义类型的方法,代码可能略长,但是还请大家仔细看,后面又解析和说明: --- ``` // bool is the set of boolean values, true and false. type bool bool // true and false are the two untyped boolean values. const ( true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. ) // uint8 is the set of all unsigned 8-bit integers. // Range: 0 through 255. type uint8 uint8 // uint16 is the set of all unsigned 16-bit integers. // Range: 0 through 65535. type uint16 uint16 // uint32 is the set of all unsigned 32-bit integers. // Range: 0 through 4294967295. type uint32 uint32 // uint64 is the set of all unsigned 64-bit integers. // Range: 0 through 18446744073709551615. type uint64 uint64 // int8 is the set of all signed 8-bit integers. // Range: -128 through 127. type int8 int8 // int16 is the set of all signed 16-bit integers. // Range: -32768 through 32767. type int16 int16 // int32 is the set of all signed 32-bit integers. // Range: -2147483648 through 2147483647. type int32 int32 // int64 is the set of all signed 64-bit integers. // Range: -9223372036854775808 through 9223372036854775807. type int64 int64 // float32 is the set of all IEEE-754 32-bit floating-point numbers. type float32 float32 // float64 is the set of all IEEE-754 64-bit floating-point numbers. type float64 float64 // complex64 is the set of all complex numbers with float32 real and // imaginary parts. type complex64 complex64 // complex128 is the set of all complex numbers with float64 real and // imaginary parts. type complex128 complex128 // string is the set of all strings of 8-bit bytes, conventionally but not // necessarily representing UTF-8-encoded text. A string may be empty, but // not nil. Values of string type are immutable. type string string // int is a signed integer type that is at least 32 bits in size. It is a // distinct type, however, and not an alias for, say, int32. type int int // uint is an unsigned integer type that is at least 32 bits in size. It is a // distinct type, however, and not an alias for, say, uint32. type uint uint // uintptr is an integer type that is large enough to hold the bit pattern of // any pointer. type uintptr uintptr // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is // used, by convention, to distinguish byte values from 8-bit unsigned // integer values. type byte = uint8 // rune is an alias for int32 and is equivalent to int32 in all ways. It is // used, by convention, to distinguish character values from integer values. type rune = int32 // any is an alias for interface{} and is equivalent to interface{} in all ways. type any = interface{} // comparable is an interface that is implemented by all comparable types // (booleans, numbers, strings, pointers, channels, interfaces, // arrays of comparable types, structs whose fields are all comparable types). // The comparable interface may only be used as a type parameter constraint, // not as the type of a variable. type comparable comparable // iota is a predeclared identifier representing the untyped integer ordinal // number of the current const specification in a (usually parenthesized) // const declaration. It is zero-indexed. const iota = 0 // Untyped int. // nil is a predeclared identifier representing the zero value for a // pointer, channel, func, interface, map, or slice type. var nil Type // Type must be a pointer, channel, func, interface, map, or slice type // Type is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type int // Type1 is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type1 int // IntegerType is here for the purposes of documentation only. It is a stand-in // for any integer type: int, uint, int8 etc. type IntegerType int // FloatType is here for the purposes of documentation only. It is a stand-in // for either float type: float32 or float64. type FloatType float32 // ComplexType is here for the purposes of documentation only. It is a // stand-in for either complex type: complex64 or complex128. type ComplexType complex64 ``` **部分类型是其他编程语言没有的,这里折重说几个类型** [scode type="green"]Bool,Uint,Int,Float,String,Byte[/scode] 仔细看前面的注释会发现有一个名为IEEE的标准,这里贴出IEEE的说明: 关于计算机和电子设备,很多标准都是按照IEEE定下的标准实施的。 > *电气电子工程师学会(IEEE)的英文全称是the Institute of Electrical and Electronics Engineers,其前身是成立于1884年的美国电气工程师协会(AIEE)和成立于1912年的无线电工程师协会(IRE)。前者主要致力于有线通讯、光学以及动力系统的研究,而后者则是国际无线电领域不断扩大的产物。20世纪30年代,“电子学”这个词开始进入工程学词典。虽然许多工程师都同时是AIEE和IRE两个协会的会员,但是新入行的电子工程师们还是更倾向于加入无线电工程师协会。两个协会之间激烈的竞争的结果,造就了双方的合作与合并。1963年,AIEE和IRE宣布合并,电气电子工程师学会(IEEE)正式成立了。* --- 引用地址:[IEEE中国](https://cn.ieee.org/about/) --- ### 布尔类型(Bool) 布尔类型分为true和false. Go的源码: ``` // bool is the set of boolean values, true and false. type bool bool // true and false are the two untyped boolean values. const ( true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. ) ``` true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. 我个人觉得这个就能很好的说明布尔类型的特性。 从抽象的角度来说,当处于0==0的情况时这是真的,因为0真的等于0,而当0!=0这种情况时,肯定就是假的。 真=true 假=false > ***布尔** (英语:**Boolean**)是[计算机科学](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6 "计算机科学")中的[逻辑数据类型](https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91%E4%BB%A3%E6%95%B0 "逻辑代数"),以发明[布尔代数](https://zh.wikipedia.org/wiki/%E5%B8%83%E6%9E%97%E4%BB%A3%E6%95%B8 "布尔代数")的数学家[乔治·布尔](https://zh.wikipedia.org/wiki/%E4%B9%94%E6%B2%BB%C2%B7%E5%B8%83%E5%B0%94 "乔治·布尔")为名。它是只有两种值的[原始类型](https://zh.wikipedia.org/wiki/%E5%8E%9F%E5%A7%8B%E9%A1%9E%E5%9E%8B "原始类型"),通常是[真](https://zh.wikipedia.org/wiki/%E7%9C%9F "真")和[假](https://zh.wikipedia.org/w/index.php?title=%E5%81%87&action=edit&redlink=1 "假(页面不存在)")。布尔数据类型主要与条件语句相关系,条件语句通过根据开发人员指定的条件式,更改程序控制流来允许评估语句的运算值为真或假(即条件成立或不成立)。这是一种更广泛的逻辑数据类型的特殊情况(参见概率逻辑)-逻辑并不总是只属于布尔类型的。 在一些语言中,布尔数据类型被定义为可代表多于两个真值。例如,ISO SQL:1999标准定义了一个SQL布尔型可以储存三个可能的值:真、假、未知(SQL [null](https://zh.wikipedia.org/wiki/%E7%A9%BA%E5%80%BC_(SQL)) "空值 (SQL)")被当作未知真值来处理,但仅仅在布尔型中使用)。在此情况下,未知先于真及假,因为布尔型一开始是未有实际值,其值是unknown(也有机会是随机值)而非真。* -- [维基百科定义](https://zh.wikipedia.org/wiki/%E5%B8%83%E6%9E%97_(%E8%B3%87%E6%96%99%E9%A1%9E%E5%9E%8B)) --- ## Uint==Byte类型 Unit的取值范围注释上很清楚了。 之所以说byte类型就是Uint类型是根据这一段源码来的: ``` // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is // used, by convention, to distinguish byte values from 8-bit unsigned // integer values. type byte = uint8 ``` Uint是无符号数,什么是无符号数呢? > **无符号数** (unsigned)是[计算机编程](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BC%96%E7%A8%8B "计算机编程")中的一种[数值](https://zh.wikipedia.org/wiki/%E6%95%B0%E5%80%BC "数值")[资料型别](https://zh.wikipedia.org/wiki/%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B "数据类型")。[有符号数](https://zh.wikipedia.org/wiki/%E6%9C%89%E7%AC%A6%E5%8F%B7%E6%95%B0 "有符号数")(signed)可以表示特定类型规定范围内的整数(包括负数),而无符号数只能表示[非负数](https://zh.wikipedia.org/wiki/%E9%9D%9E%E8%B4%9F%E6%95%B0 "非负数")(0及[正数](https://zh.wikipedia.org/wiki/%E6%AD%A3%E6%95%B0 "正数"))。--[维基百科来源](https://zh.wikipedia.org/wiki/%E6%97%A0%E7%AC%A6%E5%8F%B7%E6%95%B0) --- ## Int 类型(整数) 你可以看作是整数,包括正整数和负整数。 范围前面源码注释有,下面贴参考文献: > 在[计算机科学](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6 "计算机科学")中,**整数** 的概念指数学上[整数](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0 "整数")的一个[有限](https://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90 "有限")[子集](https://zh.wikipedia.org/wiki/%E5%AD%90%E9%9B%86 "子集")。它也称为整数数据类型,或简称**整型数** 、**整型** 。^[[1]](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)#cite_note-1)^ 通常是[程序设计语言](https://zh.wikipedia.org/wiki/%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E8%AA%9E%E8%A8%80 "程序设计语言")的一种[基础资料类型](https://zh.wikipedia.org/wiki/%E5%8E%9F%E5%A7%8B%E5%9E%8B%E6%85%8B "原始类型"),例如[java](https://zh.wikipedia.org/wiki/Java "Java")及[C](https://zh.wikipedia.org/wiki/C%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80 "C编程语言") [编程语言](https://zh.wikipedia.org/wiki/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80 "编程语言")的**int** [资料类型](https://zh.wikipedia.org/wiki/%E8%B3%87%E6%96%99%E9%A1%9E%E5%9E%8B "资料类型"),然而这种基础资料类型只能表示[有限的整数](https://zh.wikipedia.org/wiki/%E5%AD%90%E9%9B%86 "子集"),其范围受制于[电脑](https://zh.wikipedia.org/wiki/%E9%9B%BB%E8%85%A6 "电脑")的一个[字组](https://zh.wikipedia.org/wiki/%E5%AD%97_(%E8%AE%A1%E7%AE%97%E6%9C%BA)) "字 (计算机)")所包含的[比特](https://zh.wikipedia.org/wiki/%E4%BD%8D%E5%85%83 "比特")数所能表示的[组合](https://zh.wikipedia.org/wiki/%E7%B5%84%E5%90%88 "组合")总数。当运算结果超出范围时,即出现[演算溢出](https://zh.wikipedia.org/wiki/%E7%AE%97%E8%A1%93%E6%BA%A2%E5%87%BA "算术溢出"),[微处理器](https://zh.wikipedia.org/wiki/%E5%BE%AE%E8%99%95%E7%90%86%E5%99%A8 "微处理器")的状态寄存器中的溢出旗标(overflow flag)会被设置,而系统则会产生溢出例外(overflow exception)或溢出错误(overflow error)。 电脑可处理带号(signed)及非带号(unsigned)整数,非带号整数不包括负数。由于一般情况下要同时处理正数及负数,带号整数把字组的[最高有效比特](https://zh.wikipedia.org/wiki/%E6%9C%80%E9%AB%98%E6%9C%89%E6%95%88%E4%BD%8D%E5%85%83 "最高有效比特")(msb,即最左边的比特)视为正负号(**0** 代表正,**1** 代表负),而数字则以[补码](https://zh.wikipedia.org/wiki/%E4%BA%8C%E8%A3%9C%E6%95%B8 "补码")形式编码,以简化[二进制运算](https://zh.wikipedia.org/wiki/%E4%BA%8C%E9%80%B2%E5%88%B6 "二进制")的[逻辑电路](https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91%E7%94%B5%E8%B7%AF "逻辑电路")。--[维基百科](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)) --- ## Float(浮点数) 你可以看作是有着小数位的结果数,如:3.1243就是浮点数 > 在[计算机科学](https://zh.wikipedia.org/wiki/%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8 "计算机科学")中,**浮点** (英语:floating point,缩写为FP)是一种对于[实数](https://zh.wikipedia.org/wiki/%E5%AF%A6%E6%95%B8 "实数")的近似值数值表现法,由一个[有效数字](https://zh.wikipedia.org/wiki/%E6%9C%89%E6%95%88%E6%95%B0%E5%AD%97 "有效数字")(即**[尾数](https://zh.wikipedia.org/w/index.php?title=%E5%B0%BE%E6%95%B0&action=edit&redlink=1 "尾数(页面不存在)")** )加上[幂数](https://zh.wikipedia.org/wiki/%E5%86%AA%E6%95%B8 "幂数")来表示,通常是乘以某个[基数](https://zh.wikipedia.org/wiki/%E5%9F%BA%E6%95%B0_(%E5%AF%B9%E6%95%B0)) "基数 (对数)")的整数次[指数](https://zh.wikipedia.org/wiki/%E6%8C%87%E6%95%B0 "指数")得到。以这种表示法表示的数值,称为**浮点数** (floating-point number)。利用浮点进行运算,称为**浮点计算** ,这种运算通常伴随着因为无法精确表示而进行的近似或舍入。--[维基百科](https://zh.wikipedia.org/wiki/%E6%B5%AE%E7%82%B9%E6%95%B0) --- ## String字符串类型 字符串还与byte字节内容有着关联,byte中若储存的ASSCII 表所对应的内容,就可以转为人眼可识别的字符。 > **字符串** (英语:**string**),是由零个或多个[字符](https://zh.wikipedia.org/wiki/%E5%AD%97%E7%AC%A6 "字符")组成的有限序列。一般记为{\displaystyle s=a_{1}a_{2}\dots a_{n}}({\displaystyle 0\leq n\lneq \infty })。它是[编程语言](https://zh.wikipedia.org/wiki/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80 "编程语言")中表示[文本](https://zh.wikipedia.org/wiki/%E6%96%87%E6%9C%AC "文本")的[数据类型](https://zh.wikipedia.org/wiki/%E8%B3%87%E6%96%99%E5%9E%8B%E5%88%A5 "资料类型")。 > 通常以串的整体作为操作对象,如:在串中查找某个子串、求取一个子串、在串的某个位置上插入一个子串以及删除一个子串等。两个字符串相等的充要条件是:长度相等,并且各个对应位置上的字符都相等。设p、q是两个串,求q在p中首次出现的位置的运算叫做模式匹配。串的两种最基本的存储方式是顺序存储方式和链接存储方式。--[维基百科](https://zh.wikipedia.org/wiki/%E5%AD%97%E7%AC%A6%E4%B8%B2) --- ## Go语言的单独吐槽类型 ``` // any is an alias for interface{} and is equivalent to interface{} in all ways. type any = interface{} ``` 新版的sdk真离谱,让你写个泛型,你就any=interface{}就完事了,蚌埠住了。 --- ``` // nil is a predeclared identifier representing the zero value for a // pointer, channel, func, interface, map, or slice type. var nil Type // Type must be a pointer, channel, func, interface, map, or slice type // Type is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type int ``` 这两个类型也很有意思。 --- > 更新日志:2022.1.11 确认文章初版 Loading... <div class="tip inlineBlock info"> 导言 </div> 本人学过多门语言,如:JavaScript,Java,python,Golang,Kotlin等语言,以及其他小众语言。 学了越来越多的语言,最后发现语言的结果都是殊途同归的,关键字,标识符,基本类型都是围绕着已经规范了的点进行开发。 所以在这里将语言的各个情况做一个总结和规划。 希望他人看见这篇文章能够更好的学习编程语言。 本人英语并不是很好,所以有可能翻译部分数据和说法有着问题,欢迎大家讨论。 **大多数理论需要从代码方面来说,这里采用Go的代码来阐述,无论如何都是殊途同归的。** 之所以用Go是因为Go这门语言可以称之为新现代化的语言,而我个人对Go的理解勉强还行,所以从我的角度来讲就用他来说明了。 *更重要的是Go的话更容易翻看定义的源码* 因为我对于知识的理解和不断内容更新,可能文章会更新多次,文章末尾都有着更新日志。 --- ## 第一节 类型 首先这里要从操作系统的发展历史来说: 类型主要看编程语言是**强类型,弱类型**,为**OOP面向对象** ,**POP面向过程** ,**SOA面向服务** ,**AOP面向切面**,**解释型,编译型** 等。 *Go是一个编译型,更加面向过程的语言。* 这里贴入Go定义类型的方法,代码可能略长,但是还请大家仔细看,后面又解析和说明: --- ``` // bool is the set of boolean values, true and false. type bool bool // true and false are the two untyped boolean values. const ( true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. ) // uint8 is the set of all unsigned 8-bit integers. // Range: 0 through 255. type uint8 uint8 // uint16 is the set of all unsigned 16-bit integers. // Range: 0 through 65535. type uint16 uint16 // uint32 is the set of all unsigned 32-bit integers. // Range: 0 through 4294967295. type uint32 uint32 // uint64 is the set of all unsigned 64-bit integers. // Range: 0 through 18446744073709551615. type uint64 uint64 // int8 is the set of all signed 8-bit integers. // Range: -128 through 127. type int8 int8 // int16 is the set of all signed 16-bit integers. // Range: -32768 through 32767. type int16 int16 // int32 is the set of all signed 32-bit integers. // Range: -2147483648 through 2147483647. type int32 int32 // int64 is the set of all signed 64-bit integers. // Range: -9223372036854775808 through 9223372036854775807. type int64 int64 // float32 is the set of all IEEE-754 32-bit floating-point numbers. type float32 float32 // float64 is the set of all IEEE-754 64-bit floating-point numbers. type float64 float64 // complex64 is the set of all complex numbers with float32 real and // imaginary parts. type complex64 complex64 // complex128 is the set of all complex numbers with float64 real and // imaginary parts. type complex128 complex128 // string is the set of all strings of 8-bit bytes, conventionally but not // necessarily representing UTF-8-encoded text. A string may be empty, but // not nil. Values of string type are immutable. type string string // int is a signed integer type that is at least 32 bits in size. It is a // distinct type, however, and not an alias for, say, int32. type int int // uint is an unsigned integer type that is at least 32 bits in size. It is a // distinct type, however, and not an alias for, say, uint32. type uint uint // uintptr is an integer type that is large enough to hold the bit pattern of // any pointer. type uintptr uintptr // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is // used, by convention, to distinguish byte values from 8-bit unsigned // integer values. type byte = uint8 // rune is an alias for int32 and is equivalent to int32 in all ways. It is // used, by convention, to distinguish character values from integer values. type rune = int32 // any is an alias for interface{} and is equivalent to interface{} in all ways. type any = interface{} // comparable is an interface that is implemented by all comparable types // (booleans, numbers, strings, pointers, channels, interfaces, // arrays of comparable types, structs whose fields are all comparable types). // The comparable interface may only be used as a type parameter constraint, // not as the type of a variable. type comparable comparable // iota is a predeclared identifier representing the untyped integer ordinal // number of the current const specification in a (usually parenthesized) // const declaration. It is zero-indexed. const iota = 0 // Untyped int. // nil is a predeclared identifier representing the zero value for a // pointer, channel, func, interface, map, or slice type. var nil Type // Type must be a pointer, channel, func, interface, map, or slice type // Type is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type int // Type1 is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type1 int // IntegerType is here for the purposes of documentation only. It is a stand-in // for any integer type: int, uint, int8 etc. type IntegerType int // FloatType is here for the purposes of documentation only. It is a stand-in // for either float type: float32 or float64. type FloatType float32 // ComplexType is here for the purposes of documentation only. It is a // stand-in for either complex type: complex64 or complex128. type ComplexType complex64 ``` **部分类型是其他编程语言没有的,这里折重说几个类型** <div class="tip inlineBlock success"> Bool,Uint,Int,Float,String,Byte </div> 仔细看前面的注释会发现有一个名为IEEE的标准,这里贴出IEEE的说明: 关于计算机和电子设备,很多标准都是按照IEEE定下的标准实施的。 > *电气电子工程师学会(IEEE)的英文全称是the Institute of Electrical and Electronics Engineers,其前身是成立于1884年的美国电气工程师协会(AIEE)和成立于1912年的无线电工程师协会(IRE)。前者主要致力于有线通讯、光学以及动力系统的研究,而后者则是国际无线电领域不断扩大的产物。20世纪30年代,“电子学”这个词开始进入工程学词典。虽然许多工程师都同时是AIEE和IRE两个协会的会员,但是新入行的电子工程师们还是更倾向于加入无线电工程师协会。两个协会之间激烈的竞争的结果,造就了双方的合作与合并。1963年,AIEE和IRE宣布合并,电气电子工程师学会(IEEE)正式成立了。* --- 引用地址:[IEEE中国](https://cn.ieee.org/about/) --- ### 布尔类型(Bool) 布尔类型分为true和false. Go的源码: ``` // bool is the set of boolean values, true and false. type bool bool // true and false are the two untyped boolean values. const ( true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. ) ``` true = 0 == 0 // Untyped bool. false = 0 != 0 // Untyped bool. 我个人觉得这个就能很好的说明布尔类型的特性。 从抽象的角度来说,当处于0==0的情况时这是真的,因为0真的等于0,而当0!=0这种情况时,肯定就是假的。 真=true 假=false > ***布尔** (英语:**Boolean**)是[计算机科学](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6 "计算机科学")中的[逻辑数据类型](https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91%E4%BB%A3%E6%95%B0 "逻辑代数"),以发明[布尔代数](https://zh.wikipedia.org/wiki/%E5%B8%83%E6%9E%97%E4%BB%A3%E6%95%B8 "布尔代数")的数学家[乔治·布尔](https://zh.wikipedia.org/wiki/%E4%B9%94%E6%B2%BB%C2%B7%E5%B8%83%E5%B0%94 "乔治·布尔")为名。它是只有两种值的[原始类型](https://zh.wikipedia.org/wiki/%E5%8E%9F%E5%A7%8B%E9%A1%9E%E5%9E%8B "原始类型"),通常是[真](https://zh.wikipedia.org/wiki/%E7%9C%9F "真")和[假](https://zh.wikipedia.org/w/index.php?title=%E5%81%87&action=edit&redlink=1 "假(页面不存在)")。布尔数据类型主要与条件语句相关系,条件语句通过根据开发人员指定的条件式,更改程序控制流来允许评估语句的运算值为真或假(即条件成立或不成立)。这是一种更广泛的逻辑数据类型的特殊情况(参见概率逻辑)-逻辑并不总是只属于布尔类型的。 在一些语言中,布尔数据类型被定义为可代表多于两个真值。例如,ISO SQL:1999标准定义了一个SQL布尔型可以储存三个可能的值:真、假、未知(SQL [null](https://zh.wikipedia.org/wiki/%E7%A9%BA%E5%80%BC_(SQL)) "空值 (SQL)")被当作未知真值来处理,但仅仅在布尔型中使用)。在此情况下,未知先于真及假,因为布尔型一开始是未有实际值,其值是unknown(也有机会是随机值)而非真。* -- [维基百科定义](https://zh.wikipedia.org/wiki/%E5%B8%83%E6%9E%97_(%E8%B3%87%E6%96%99%E9%A1%9E%E5%9E%8B)) --- ## Uint==Byte类型 Unit的取值范围注释上很清楚了。 之所以说byte类型就是Uint类型是根据这一段源码来的: ``` // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is // used, by convention, to distinguish byte values from 8-bit unsigned // integer values. type byte = uint8 ``` Uint是无符号数,什么是无符号数呢? > **无符号数** (unsigned)是[计算机编程](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BC%96%E7%A8%8B "计算机编程")中的一种[数值](https://zh.wikipedia.org/wiki/%E6%95%B0%E5%80%BC "数值")[资料型别](https://zh.wikipedia.org/wiki/%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B "数据类型")。[有符号数](https://zh.wikipedia.org/wiki/%E6%9C%89%E7%AC%A6%E5%8F%B7%E6%95%B0 "有符号数")(signed)可以表示特定类型规定范围内的整数(包括负数),而无符号数只能表示[非负数](https://zh.wikipedia.org/wiki/%E9%9D%9E%E8%B4%9F%E6%95%B0 "非负数")(0及[正数](https://zh.wikipedia.org/wiki/%E6%AD%A3%E6%95%B0 "正数"))。--[维基百科来源](https://zh.wikipedia.org/wiki/%E6%97%A0%E7%AC%A6%E5%8F%B7%E6%95%B0) --- ## Int 类型(整数) 你可以看作是整数,包括正整数和负整数。 范围前面源码注释有,下面贴参考文献: > 在[计算机科学](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6 "计算机科学")中,**整数** 的概念指数学上[整数](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0 "整数")的一个[有限](https://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90 "有限")[子集](https://zh.wikipedia.org/wiki/%E5%AD%90%E9%9B%86 "子集")。它也称为整数数据类型,或简称**整型数** 、**整型** 。^[[1]](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)#cite_note-1)^ 通常是[程序设计语言](https://zh.wikipedia.org/wiki/%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E8%AA%9E%E8%A8%80 "程序设计语言")的一种[基础资料类型](https://zh.wikipedia.org/wiki/%E5%8E%9F%E5%A7%8B%E5%9E%8B%E6%85%8B "原始类型"),例如[java](https://zh.wikipedia.org/wiki/Java "Java")及[C](https://zh.wikipedia.org/wiki/C%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80 "C编程语言") [编程语言](https://zh.wikipedia.org/wiki/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80 "编程语言")的**int** [资料类型](https://zh.wikipedia.org/wiki/%E8%B3%87%E6%96%99%E9%A1%9E%E5%9E%8B "资料类型"),然而这种基础资料类型只能表示[有限的整数](https://zh.wikipedia.org/wiki/%E5%AD%90%E9%9B%86 "子集"),其范围受制于[电脑](https://zh.wikipedia.org/wiki/%E9%9B%BB%E8%85%A6 "电脑")的一个[字组](https://zh.wikipedia.org/wiki/%E5%AD%97_(%E8%AE%A1%E7%AE%97%E6%9C%BA)) "字 (计算机)")所包含的[比特](https://zh.wikipedia.org/wiki/%E4%BD%8D%E5%85%83 "比特")数所能表示的[组合](https://zh.wikipedia.org/wiki/%E7%B5%84%E5%90%88 "组合")总数。当运算结果超出范围时,即出现[演算溢出](https://zh.wikipedia.org/wiki/%E7%AE%97%E8%A1%93%E6%BA%A2%E5%87%BA "算术溢出"),[微处理器](https://zh.wikipedia.org/wiki/%E5%BE%AE%E8%99%95%E7%90%86%E5%99%A8 "微处理器")的状态寄存器中的溢出旗标(overflow flag)会被设置,而系统则会产生溢出例外(overflow exception)或溢出错误(overflow error)。 电脑可处理带号(signed)及非带号(unsigned)整数,非带号整数不包括负数。由于一般情况下要同时处理正数及负数,带号整数把字组的[最高有效比特](https://zh.wikipedia.org/wiki/%E6%9C%80%E9%AB%98%E6%9C%89%E6%95%88%E4%BD%8D%E5%85%83 "最高有效比特")(msb,即最左边的比特)视为正负号(**0** 代表正,**1** 代表负),而数字则以[补码](https://zh.wikipedia.org/wiki/%E4%BA%8C%E8%A3%9C%E6%95%B8 "补码")形式编码,以简化[二进制运算](https://zh.wikipedia.org/wiki/%E4%BA%8C%E9%80%B2%E5%88%B6 "二进制")的[逻辑电路](https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91%E7%94%B5%E8%B7%AF "逻辑电路")。--[维基百科](https://zh.wikipedia.org/wiki/%E6%95%B4%E6%95%B0_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)) --- ## Float(浮点数) 你可以看作是有着小数位的结果数,如:3.1243就是浮点数 > 在[计算机科学](https://zh.wikipedia.org/wiki/%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8 "计算机科学")中,**浮点** (英语:floating point,缩写为FP)是一种对于[实数](https://zh.wikipedia.org/wiki/%E5%AF%A6%E6%95%B8 "实数")的近似值数值表现法,由一个[有效数字](https://zh.wikipedia.org/wiki/%E6%9C%89%E6%95%88%E6%95%B0%E5%AD%97 "有效数字")(即**[尾数](https://zh.wikipedia.org/w/index.php?title=%E5%B0%BE%E6%95%B0&action=edit&redlink=1 "尾数(页面不存在)")** )加上[幂数](https://zh.wikipedia.org/wiki/%E5%86%AA%E6%95%B8 "幂数")来表示,通常是乘以某个[基数](https://zh.wikipedia.org/wiki/%E5%9F%BA%E6%95%B0_(%E5%AF%B9%E6%95%B0)) "基数 (对数)")的整数次[指数](https://zh.wikipedia.org/wiki/%E6%8C%87%E6%95%B0 "指数")得到。以这种表示法表示的数值,称为**浮点数** (floating-point number)。利用浮点进行运算,称为**浮点计算** ,这种运算通常伴随着因为无法精确表示而进行的近似或舍入。--[维基百科](https://zh.wikipedia.org/wiki/%E6%B5%AE%E7%82%B9%E6%95%B0) --- ## String字符串类型 字符串还与byte字节内容有着关联,byte中若储存的ASSCII 表所对应的内容,就可以转为人眼可识别的字符。 > **字符串** (英语:**string**),是由零个或多个[字符](https://zh.wikipedia.org/wiki/%E5%AD%97%E7%AC%A6 "字符")组成的有限序列。一般记为{\displaystyle s=a_{1}a_{2}\dots a_{n}}({\displaystyle 0\leq n\lneq \infty })。它是[编程语言](https://zh.wikipedia.org/wiki/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80 "编程语言")中表示[文本](https://zh.wikipedia.org/wiki/%E6%96%87%E6%9C%AC "文本")的[数据类型](https://zh.wikipedia.org/wiki/%E8%B3%87%E6%96%99%E5%9E%8B%E5%88%A5 "资料类型")。 > 通常以串的整体作为操作对象,如:在串中查找某个子串、求取一个子串、在串的某个位置上插入一个子串以及删除一个子串等。两个字符串相等的充要条件是:长度相等,并且各个对应位置上的字符都相等。设p、q是两个串,求q在p中首次出现的位置的运算叫做模式匹配。串的两种最基本的存储方式是顺序存储方式和链接存储方式。--[维基百科](https://zh.wikipedia.org/wiki/%E5%AD%97%E7%AC%A6%E4%B8%B2) --- ## Go语言的单独吐槽类型 ``` // any is an alias for interface{} and is equivalent to interface{} in all ways. type any = interface{} ``` 新版的sdk真离谱,让你写个泛型,你就any=interface{}就完事了,蚌埠住了。 --- ``` // nil is a predeclared identifier representing the zero value for a // pointer, channel, func, interface, map, or slice type. var nil Type // Type must be a pointer, channel, func, interface, map, or slice type // Type is here for the purposes of documentation only. It is a stand-in // for any Go type, but represents the same type for any given function // invocation. type Type int ``` 这两个类型也很有意思。 --- > 更新日志:2022.1.11 确认文章初版 最后修改:2022 年 01 月 11 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏
1 条评论
测试一些邮件