当前位置:网站首页>Go learning notes (2) basic types and statements (1)
Go learning notes (2) basic types and statements (1)
2022-07-07 23:54:00 【Raring_ Ringtail】

This section is about go Basic types and declarations of ,go On the whole, the basic types of are not much different from other languages , but go The basic types of languages also have their own characteristics .
Built in type
Zero value
go All variables that are defined but not assigned a value will be assigned a zero value , Each type has its own zero value .
Literal
go There are five literal quantities , Include common integers 、 Floating point numbers 、 character 、 Strings and less common complex numeric facets .
The whole number area
There are the following kinds of integer face quantities :
0bIt starts with binary numbersfmt.Println(0b111) // Output 70oIt starts with an octal numberfmt.Println(0o11) // Output 90xIt starts with a hexadecimal numberfmt.Println(0xff) // Output 255- What has no prefix is decimal number
fmt.Println(22) // Output 22
For long strings of numbers go It is allowed to underline numbers
fmt.Println(1_234_5_6_789) // Output 123456789
Floating point face count
Floating point number facets are similar to integer number facets
fmt.Println(1.2345) // Output 1.2345
It can be used e To represent scientific notation 10 The power of
fmt.Println(1.2345e2) // Output 123.45
Hexadecimal floating-point number facets are troublesome to interpret , Just look at the examples :0xa.bpc Represents a hexadecimal number a.b ride 2^c,p It's similar to the above e, Express 2 The power of .
0x1p-2 // == 1.0/4 == 0.25
0x2.p10 // == 2.0 * 1024 == 2048.0
0xap0 // == 10*1 == 10
0x0.1p0 // == 1/16*1 == 0.0625
Similarly, underscores can also be used in floating-point numbers
fmt.Println(1.23_45) // Output 1.2345
Rune (rune) Literal
stay go Through... In language rune Literal quantity can realize the representation of various characters , Actually, one. rune Literal quantity is a int32 Type of number .rune Literal quantity can use single quotation marks '' Cover up .
Use fmt.Println() Print rune The numeric value of literal quantity will be printed by default , If you want to print out the characters it represents, you need to convert them into string type
fmt.Println('a') // Output 97
fmt.Println(string('\u0061')) // Output a
fmt.Println(string(128514)) // Output
Literal of a string
stay go There are two languages , One is to use double quotation marks "" The enclosed , Another is to use backquotes `` The enclosed .
String literals enclosed in double quotation marks are basically similar to those in other languages .
fmt.Println(" Notes on Jiangda ") // Output Jiangda notes
Use back quotes `` The enclosed string can contain any character except backquotes .
This makes it very suitable for quoting large paragraphs of text without worrying about line breaks and indentations , Strings quoted in backquotes are saved intact .
fmt.Println(`----
Big is not much Haina river
There is no limit to learning Between heaven and earth `)
// Here is the output :
//----
// Big is not much Haina river
// There is no limit to learning Between heaven and earth
Welcome to my WeChat official account. Notes on Jiangda
边栏推荐
- Robomaster visual tutorial (10) target prediction
- Ora-01741 and ora-01704
- 机器人(自动化)等专业课程创新的结果
- HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
- Kubectl's handy command line tool: Oh my Zsh tips and tricks
- gorm 关联关系小结
- 网上买基金安全么?
- ping报错:未知的名称或服务
- Chisel tutorial - 01 Introduction to Scala
- Chisel tutorial - 04 Control flow in chisel
猜你喜欢

FFA and ICGA angiography

【路径规划】使用垂距限值法与贝塞尔优化A星路径

Aitm3.0005 smoke toxicity test

Seven years' experience of a test engineer -- to you who walk alone all the way (don't give up)
![[leetcode] 20. Valid brackets](/img/42/5a2c5ec6c1a7dbcdfb2226cdea6a42.png)
[leetcode] 20. Valid brackets

HB 5469民用飞机机舱内部非金属材料燃烧试验方法

Solutions to problems in sqlserver deleting data in tables

DataGuard active / standby cleanup archive settings

About the difference between ch32 library function and STM32 library function

激光slam学习(2D/3D、偏实践)
随机推荐
Uic564-2 Appendix 4 - flame retardant fire test: flame diffusion
[path planning] use the vertical distance limit method and Bessel to optimize the path of a star
Balanced binary tree [AVL tree] - insert, delete
Take you hand in hand to build Eureka client with idea
@Configuration注解的详细介绍
FFA与ICGA造影
保证接口数据安全的10种方案
Traduction gratuite en un clic de plus de 300 pages de documents PDF
快速回复二极管整流特性
gorm 关联关系小结
codeforces每日5题(均1500)-第八天
[experiment sharing] log in to Cisco devices through the console port
数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
limit 与offset的用法(转载)
One click installation with fishros in blue bridge ROS
Dataguard 主备清理归档设置
Resolve the URL of token
P1308 [noip2011 popularity group] count the number of words
Where are you going
Chisel tutorial - 00 Ex.scala metals plug-in (vs Code), SBT and coursier exchange endogenous