当前位置:网站首页>Go data types (II) overview of data types supported by go and Boolean types
Go data types (II) overview of data types supported by go and Boolean types
2022-06-23 08:17:00 【weixin_ fifty-nine million two hundred and eighty-four thousand】
Go Supported data types
Go The language has built-in support for these basic data types :
- Boolean type :bool
- integer :int8、byte、int16、int、uint、uintptr etc.
- Floating point type :float32、float64
- Plural type :complex64、complex128
- character string :string
- Character type :rune
- Wrong type :error
Besides ,Go The language also supports the following composite types :
- The pointer (pointer)
- Array (array)
- section (slice)
- Dictionaries (map)
- passageway (chan)
- Structure (struct)
- Interface (interface)
Unlike other static languages ,Go Added a new channel type , This type is mainly used for communication between different coroutines during concurrent programming , Later on Go Language concurrent programming will be introduced in detail .
Structs are similar to classes in object-oriented programming languages (class),Go Continue to use C This compound type of language , Instead of introducing a separate class concept like traditional object-oriented programming ,Go The language also presents interfaces as a single type , Later on Go The use of these two types will be introduced in detail during object-oriented programming .
Boolean type
Go The Boolean types in this language are similar to those in other mainstream programming languages , Type keyword is bool, Can be assigned and can only be assigned to predefined constants true and false. The sample code is as follows :
var v1 bool
v1 = true
v2 := (1 == 2) // v2 It will also be deduced as bool type Go It's a strongly typed language , Once the variable type is determined , You cannot assign values of other types to this variable , therefore , Boolean types cannot accept assignments of other types , Automatic or forced type conversions are not supported . The following examples are some of the wrong uses , Causes a compilation error :
var b bool
b = 1 // Compile error
b = bool(1) // Compile error However, the boolean result calculated by the expression can be assigned to Go Boolean type variable :
var b bool
b = (1!=0) // Compile correctly
fmt.Println("Result:", b) // The result is Result: true Besides , Due to strong typing ,Go When a language judges whether a Boolean value is true or false , There are strict restrictions on the types of values , stay PHP In this weakly typed language , The following values are used in Boolean judgment ( Use non strict == Comparison symbol ) Will be considered as false(JavaScript、Python Also similar ):
- Boolean value
FALSEIn itself - integer
0( zero ) - Floating point value
0.0( zero ) - An empty string , And strings “0”
- An array that does not include any elements
- Special type NULL( Include variables that have not been assigned )
- Generated from empty tags SimpleXML object
And in the Go Not in language , Values of different types cannot be used == or != Operator to compare , Errors will be reported at compile time , For example, the following code :
b := (false == 0);The following errors will be reported during compilation :
annot convert 0 (type untyped number) to type bool
invalid operation: false == 0 (mismatched types bool and int) Again ,! Operators also cannot act on non Boolean values .
边栏推荐
- After reading five books, I summarized these theories of wealth freedom
- How to start Jupiter notebook in CONDA virtual environment
- socket编程(多进程)
- jmeter压测结果分析
- Go 数据类型篇(二)之Go 支持的数据类型概述及布尔类型
- Map接口及其子实现类
- What are open source software, free software, copyleft and CC? Can't you tell them clearly?
- Crawler frame
- Image segmentation - improved network structure
- 数据资产为王,解析企业数字化转型与数据资产管理的关系
猜你喜欢

实战监听Eureka client的缓存更新

走好数据中台最后一公里,为什么说数据服务API是数据中台的标配?

Vulnhub | DC: 3 |【实战】

图像分割-改进网络结构

Introduction to Excel VBA and practical examples

Deep learning ----- different methods to realize vgg16

Vulnhub | DC: 4 |【实战】

After reading five books, I summarized these theories of wealth freedom

RTSP/ONVIF协议视频平台EasyNVR启动服务报错“service not found”,该如何解决?

Ad object of Active Directory
随机推荐
PHP 文件包含 -ctf
C RichTextBox controls the maximum number of rows
Production environment server environment setup + project release process
View the file once a second and send the result of the last line of the file to the syslog server
力扣(LeetCode)173. 二叉搜索树迭代器(2022.06.22)
socket编程——select模型
MFC radio button grouping
Vulnhub | DC: 4 |【实战】
Image segmentation - improved network structure
船长阿布的灵魂拷问
vtk.js鼠標左鍵滑動改變窗比特和窗寬
Huawei ECS EIP cannot be pinged
忽略超长参数违规
Active Directory之AD对象
After easynvr video is enabled, no video file is generated. How to solve this problem?
开源技术交流丨批流一体数据同步引擎ChunJun数据还原-DDL功能模块解析
For loop of go language foundation
Socket programming (multi process)
MySQL common skills
Tencent cloud account related