Go Basic Types

Basic Types

 TypeBytesDefaultDescription
 bool1falseBoolean values only have two values: true and false
 byte10uint8
 rune40int32,often used for processing Unicode
Integerint,uint4 or 80For 32-bit operating systems, it's 4; for 64-bit operating systems, it's 8
int8,uint810 
int16,uint1620 
int32,uint3240 
int64,uint6480 
Floatfloat3240.0 
float6480.0 
Complexcomplex648  
complex12816  
 uintptr4 or 8 uint32 or uint64,used to store memory addresses
 array   
 struct  The zero value of the corresponding type for each field in a struct
 string “”Encoded in UTF-8 and enclosed in double quotes
 slice nilReference Types
 map nilReference Types
 channel nilReference Types
 interface nil 
 function nil 

 

Multiline Strings (Backticks)

In Go, to define a multiline string, you must use backtick characters:

s1 := `1st line
   2nd line
   3rd line
   `

Common String Operations

FunctionsDescription
len(str)Get the length of a string
+ or fmt.SprintfCombine two or more strings
strings.SplitDivide a string into substrings based on a delimiter
strings.ContainsCheck if a string contains a specific substring
strings.HasPrefix,strings.HasSuffixVerify if a string starts or ends with a certain sequence
strings.Index(),strings.LastIndex()Find the position of a substring within a string
strings.JoinCombine multiple strings into a single string using a separator

 

Type Conversion

Go only supports explicit type conversion, not implicit. It can only be used when the two types involved support mutual conversion. The basic syntax for explicit type conversion is as follows:

T(expression)

Where T represents the type to convert to, and expression can include variables, function return values, etc.

Take a break

👉👉👉 【Jade Dynasty EP44】Gui Li escaped from the Fire Altar, and Xiao Bai transformed into a beauty