当前位置:网站首页>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 .
边栏推荐
- MySQL common skills
- Image segmentation - improved network structure
- Idea true permanent activation method and permanent activation code tutorial
- QT irregular shape antialiasing
- Huawei ECS EIP cannot be pinged
- INT 104_ LEC 06
- 6-闪耀的激光-CALayer 的应用
- Moodle e-learning platform fixes the session hijacking error that leads to pre authorized rce
- odoo项目 发送信息到微信公众号或企业微信的做法
- For loop of go language foundation
猜你喜欢

ArcMap batch delete points closer

如何在conda虚拟环境开启jupyter-notebook

PHP file contains -ctf

Rotary table visual screening machine and its image recognition system

openvino系列 19. OpenVINO 与 PaddleOCR 实现视频实时OCR处理

jmeter压测结果分析

On ThreadLocal and inheritablethreadlocal, source code analysis

开源软件、自由软件、Copyleft、CC都是啥,傻傻分不清楚?

Imperva- method of finding regular match timeout

INT 104_LEC 06
随机推荐
PCB电路板特性检查项目都有哪些?
配置ASMX无法访问
【Try to Hack】ip地址
After reading five books, I summarized these theories of wealth freedom
PHP serialization and deserialization CTF
What are open source software, free software, copyleft and CC? Can't you tell them clearly?
[try to hack] IP address
The kernel fails to shut down when the easygbs program stops. How should I optimize it? [code attached]
目标检测中的多尺度特征结合方式
3-ProgressBar和二次裁剪
Vulnhub | dc: 4 | [actual combat]
Regular expression use cases
Easycvr accesses the website through the domain name. How to solve the problem that the video cannot be viewed back?
INT 104_LEC 06
After easynvr video is enabled, no video file is generated. How to solve this problem?
odoo项目 发送信息到微信公众号或企业微信的做法
81 sentences worth repeating
How to solve the problem that flv video stream cannot be played and TS file generation fails due to packet loss?
Location of firewalld configuration file
数据资产为王,解析企业数字化转型与数据资产管理的关系