当前位置:网站首页>2. Basic knowledge of golang
2. Basic knowledge of golang
2022-07-07 15:16:00 【Indulge fly】
Catalog
3. Naming specification ( Suggest )
1. identifier
identifier : Just name it , The composition rules are as follows
1. Identifiers are made up of letters , Numbers and underscores
2. Cannot start with a number
3. Identifiers are case sensitive 2. keyword
1. Keywords are built-in characters , Cannot be used as an identifier
2. common 25 Two keywords and 36 Predefined identifiers
3. Don't have to remember , You'll get familiar with it slowly 3. Naming specification ( Suggest )
1.Go It's case sensitive language
2. When an identifier is referenced as an external package , The first letter should be capitalized
When the identifier is not visible by outsourcing , Initial lowercase
3. Package name :
Any one of them go Files can be referenced as packages ,
After naming the package name (package Package name ) when , Try to keep consistent with the directory , Or meaningful
4.go File naming : A lowercase letter + Underline
5. Structure naming : Hump nomenclature
6. The interface name : With "er" ending
7. Constant naming : All capitals + Underline
8. unit testing : The file is named with "_test.go" ending , The function name is "Test" start 4. Variable
1. The variable of reputation cannot be repeated , And after the declaration, you must use
2. Externally declared variables :var Variable name Variable type
3. Batch variable declaration :
var(
name string
sex string
age int
)
4. Variable initialization : use = assignment
var name = "fly"
5. Variable type derivation : During initialization , Don't declare data types ,go Internal will automatically deduce
var(
name = "fly"
age = 18
sex = "man"
)
6. Initialize multiple variables : Separated by commas , One to one assignment
var name, age, sex = "fly", 18, "man"
7. Short variable declaration : Refers to variables declared inside a function , You don't have to write var, use ":="
fun main() {
name := "zcy"
age = 18
sex = "man"
}
8. Anonymous variables : When receiving variables as parameters , Unused variables are underlined "_" Instead of
package main
import "fmt"
func getNameAge() (string, int) {
return "fly", 18
}
func main() {
name, _ := getNameAge()
fmt.Printf("name: %v\n", name)
}
9. notes :
Single-line comments : Double diagonal bar // ctrl + /
Multiline comment :/* */ alt + shif t+ a5. Constant
1. Concept : Constants are defined in the compilation stage , Unalterable
2. Constant definition : Use keywords const
usage :const Constant names type = Constant values
3. Because when defining constants, you must assign values , So constant types can be omitted
4. Batch definition constants
const (
width = 100
height = 100
)
5. When defining constants in batch , If the following constant omits the assignment , The default is the same as the previous variable
const (
hight = 100 // 100
weidth // 100
name = "fly" // fly
age // fly
)
6. Continuous definition ( Multiple assignments ):
const width, height = 100, 100
7.iota
(1)iota Is a constant that can be modified by the compiler , The default is 0, Every time you call +1, encounter const When the reset to 0
(2) Both constants define iota, There is a gap between the two "_" Or ordinary constants ,iota The value of will still jump
const (
a = iota // 0
_ // encounter "_",iota still +1, here =1
b = iota // 2
c = 1 // 1 Encountered a common variable ,iota still +1, here =3
d = iota // 4
)6. Data type classification
1. Boolean type
2. Numeric type ( integer , floating-point )
3. String type ( Fixed length )
4. Derived type ( Pointer types , An array type , Structured type ,Channel type , Function type , Slice type , Interface type (interface),Map type )7. Basic supplement
1. Judge if
if Conditions {
The body of the function
} else {
The body of the function
}
2. loop for
for The initial state ; Conditions ; State change {
The body of the function
}
3. And :&&
4. Print variables
fmt.Println( Variable )
5. Format printing
fmt.Printf("%v\n", Variable )
difference :Println Bring your own line feed
5. Print symbols
Print data :%v
fmt.Printf("%v\n", "FLY") // FLY
Print data type :%T
fmt.Printf("%T\n", "fly") // string
Print number type integer size :%dB
fmt.Printf("%dB\n", 18) // 18B8. Boolean type
true,false
effect : In conditional judgment , loop , Logical expression, etc , Used to judge true or false
Be careful :golang Boolean type in , You can't use numbers (0 Or not 0) Express true and false
package main
import "fmt"
func main() {
age = 200
// error
if age {
fmt.Println(" error ")
}
// correct
if age>1 {
fmt.Println(" correct ")
}
}9. Numeric type
1. Include : Integer and floating point , Primitive plural , Bit operation uses complement
2. integer :int integer ,uint Unsigned integer ,uintptr Unsigned integer with fixed length to store pointer
3.int And uint stay 32 Bit on the operating system 4 Bytes , stay 64 Bit on the operating system 8 Bytes
4.go The sizes of the types in are fixed ( understand ), among int Type is the fastest kind of calculation
5. floating-point :float32 And float64( Add : Floating point numbers in computers are imprecise !)
(1) The integer zero value is 0, Floating point zero is 0.0
(2) Format and print floating point :
Full print :%f
Take two digits to print :%.2f
6. Hexadecimal conversion Binary format output
Decimal system :%d
Binary system :%b
octal :%o
Hexadecimal :%x or %X
7. The plural :
32 position :complex64
64 position :complex128边栏推荐
- CTFshow,信息搜集:web7
- How bad can a programmer be? Nima, they are all talents
- Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)
- 时空可变形卷积用于压缩视频质量增强(STDF)
- Niuke real problem programming - Day12
- Connecting FTP server tutorial
- 什么是数据泄露
- CTFshow,信息搜集:web1
- Delete a whole page in word
- Why do we use UTF-8 encoding?
猜你喜欢

Ctfshow, information collection: web7

众昂矿业:萤石继续引领新能源市场增长

How to enable radius two factor / two factor (2fa) identity authentication for Anheng fortress machine

Ctfshow, information collection: web12

asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design

#HPDC智能基座人才发展峰会随笔

写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
![[server data recovery] data recovery case of raid failure of a Dell server](/img/5d/03bc8dcc6e554273b34a78c49a9eaf.jpg)
[server data recovery] data recovery case of raid failure of a Dell server

Niuke real problem programming - Day17

8大模块、40个思维模型,打破思维桎梏,满足你工作不同阶段、场景的思维需求,赶紧收藏慢慢学
随机推荐
Read PG in data warehouse in one article_ stat
Shengteng experience officer Episode 5 notes I
Protection strategy of server area based on Firewall
word中删除一整页
CTFshow,信息搜集:web6
Ctfshow, information collection: web12
使用Scrapy框架爬取网页并保存到Mysql的实现
Cocoscreator operates spine for animation fusion
Connecting FTP server tutorial
Niuke real problem programming - day16
MySQL bit type resolution
Ctfshow, information collection: web5
Andriod --- JetPack :LiveData setValue 和 postValue 的区别
Niuke real problem programming - Day10
MySQL installation configuration 2021 in Windows Environment
避坑:Sql中 in 和not in中有null值的情况说明
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
CTFshow,信息搜集:web10
【原创】一切不谈考核的管理都是扯淡!