Golang package builtin 中内置函数我分为两部分介绍,第一部分为基础类型,第二部分为包含函数、接口,较复杂一些

第一部分

// 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

主要注意几个点:

  • type int int 大小至少32位也就是至少4字节,为什么说是至少呢?因为int类型所占字节数跟操作系统有关,如果是32位就是4个字节,如果是64位就是8个字节,type int inttype int32 int32不同,int32永远是32位,int64永远是64位。
  • type string string string可能是空,但不能为nil,这一点和Java不同,Java中String可以为null。string是不可变的,这一点和Java相同。
  • type uintptr uintptr 是一个integer类型,空间足够大可存储任何指针。
  • byteuint8类型是相同的,可以说是uint8的别称,byte更简单一些。
  • runeint32类型是相同的,rune更简单一些。

第二部分

any

// any is an alias for interface{} and is equivalent to interface{} in all ways.
type any = interface{}

anyinterface{} 是相同的,不要以为是泛型关键词,为了少写一些字母所以会用any,下面举了一个例子

 func convert(t any){switch t.(type){case int://case string://case bool://}}func main() {f(2)f(true)f("煎鱼好!")}

comparable

// comparable is an interface that is implemented by all comparable types
// (booleans, numbers, strings, pointers, channels, 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 interface{ comparable }

comparable是由所有可比较类型(包括booleans, numbers, strings, pointers, channels,interface, arrays中元素为可比较类型,
以及structs 中所有属性都是可比较类型)实现的接口。只能用于类型参数约束,不用于变量类型比较,举个

【源码阅读】【苦练基本功】Golang内置函数分析相关推荐

  1. Golang 内置函数

    Golang中内置了一些函数,在使用这些函数时,不必以包名为前缀来调用,而是直接写函数名即可调用,这些函数都是一些基础的函数,在程序设计中应用比较普遍,所以一定要牢记这些最基本的函数用法.下边来介绍一 ...

  2. golang内置函数

    Go 语言拥有一些不需要进行导入操作就可以使用的内置函数.它们有时可以针对不同的类型进行操作,例如:len.cap 和 append,或必须用于系统级的操作,例如:panic.因此,它们需要直接获得编 ...

  3. 多城市教育培训机构行业企业站群系统源码-强大的SEO功能-内置三千多个城市

    简介: 多城市教育培训机构行业企业站群系统源码,强大的SEO功能,内置三千多个城市. 重点说明: 仅限win服务器安装使用,Linux系统安装站点后台存在一些问题 强大SEO功能,城市分站自主选择,数 ...

  4. [PHP源码阅读]trim、rtrim、ltrim函数

    trim系列函数是用于去除字符串中首尾的空格或其他字符.ltrim函数只去除掉字符串首部的字符,rtrim函数只去除字符串尾部的字符. 我在github有对PHP源码更详细的注解.感兴趣的可以围观一下 ...

  5. trim函数 php,[PHP源码阅读]trim、rtrim、ltrim函数

    trim系列函数是用于去除字符串中首尾的空格或其他字符.ltrim函数只去除掉字符串首部的字符,rtrim函数只去除字符串尾部的字符. 我在github有对PHP源码更详细的注解.感兴趣的可以围观一下 ...

  6. PHP yii 框架源码阅读(二) - 整体执行流程分析

    转载链接:http://tech.ddvip.com/2013-11/1384432766205970.html 一  程序入口 <?php// change the following pat ...

  7. 【蓝牙sbc协议】sbc源码阅读笔记(四)——sbc_encode函数详解

    sbc_encode函数详解 函数定义: // sbc.c SBC_EXPORT ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t in ...

  8. map内置函数分析所得到的思路

    map:会根据提供的函数对指定序列做映射. map(func, *iterables) --> map objectMake an iterator that computes the func ...

  9. php内置函数分析之strtoupper()、strtolower()

    strtoupper(): 1 PHP_FUNCTION(strtoupper)2 {3 zend_string *str;4 5 ZEND_PARSE_PARAMETERS_START(1, 1)6 ...

最新文章

  1. 昨天在公司加班,上午好像就是弄一个ftp的linux服务问题
  2. python 删除第三方库_python 安装移动复制第三方库操作
  3. Leetcode: Single Number
  4. ARGB和PARGB
  5. mysql的优化-添加环境变量启动服务
  6. 查看函数说明_Axure函数使用说明
  7. 用jsp开发web应用并不是一个高效率的选择
  8. 使用threeJS根据点的坐标绘制曲线
  9. 给职场人士的四点良心建议
  10. css盒模型与层模型与定位
  11. Apple Silicon配置二进制环境(一)
  12. python经纬度转换xy坐标公式_经纬度坐标转换为距离及角度(Python)
  13. 校园火灾项目结合Focus
  14. android 内存分析工具ASAN 学习
  15. Open3d读写pcd点云文件
  16. 完数(难度系数:半颗星)
  17. 面向单片机编程(三)- 数码管显示
  18. 是终点也是起点:你的恋爱目标是什么?
  19. 计算机系统在英语中的运用,在应用系统中探究计算机屏幕英语句法规律.doc
  20. 山东大学软件学院2022年数据库课程设计环境配置教程

热门文章

  1. c语言iota函数,C++ iota函数用法详解
  2. 写给自己:入职两个月的收获与变化
  3. 数据网格(Data Mesh)是什么?
  4. DHT11温湿度传感器——基于arduino
  5. windows7以上平台 NDISFilter 网卡过滤驱动开发
  6. 从罗永浩进军AR聊开
  7. c语言atm程序个人总结,C语言程序设计报告(模拟ATM取款机)
  8. python timeit.timer_python之timeit模块
  9. 通过iptables 禁止访问域名方法整合
  10. Jupyter Notebook 五大效率插件