MindMap Gallery GO basic syntax
Describes the syntax used when learning the GO language, with code attached. It can be used as an introduction to comparative learning of GO language. If there are any additions later, a new map will be published on the work page.
Edited at 2024-01-23 15:35:28Avatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
Avatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
GO basic syntax
basic grammar
main function
package declaration
Can be different from the name directory
The declaration of the test file can be added with the _test suffix
The declarations of .go files in the same directory must be consistent, and the declarations of test files must also be consistent.
Accessibility
Capitalized means it can be accessed outside the package.
Lowercase can only be accessed within the package
basic type
int family (can express positive and negative numbers)
int
The number of bytes used by int depends on the CPU
int8
1 byte
int16
2 bytes
int32
4 bytes
int64
8 bytes
unit family (unsigned integer) (can only express positive numbers)
uint
How many bytes are used by uint depends on the CPU
uint8
1 byte
uint16
2 bytes
uint32
4 bytes
uint64
8 bytes
float family
float32
4zijie
float64
8 bytes
string
For splicing
Auxiliary usage using strings package
The double quotes "" inside Println() need to be escaped, otherwise it will cause output errors. When escaping, you can write the content to be output and then copy it into the double quotes, so that the compiler can automatically escape
Println() can also use backticks ` `, and newlines can be added inside the backticks.
When splicing strings, you cannot connect numbers. You need to convert the numbers into strings first and then splice them. Use strconv.Itoa(123) to convert 123 into a string.
What you get using the function len() is the byte length of the string, not the number of characters. Use utf8.RuneCountInString() to get the number of characters
byte type
It is bytes, essentially uint8, which is also used to represent ASCII codes. The corresponding operations are in the bytes package.
[ ]byte slices can be converted to and from strings.
var a [ ]byte = 'a' When assigning a value using single quotes, you can only use a single character. At this time, the ASCII code value of a is 97.
var a [ ]byte = "hello" can be assigned to a string when using double quotes
bool type
And: (a && b)
OrOr:( a || b)
Negation: (!a)
computation
The math package has more auxiliary uses
Hold down the command and click on the package function to jump into the package to see the relevant explanations.
Both sides of the operation must be of the same type. Int and int64 cannot be operated together and must be converted to the same type before operation.
Integers and integer operation results are also integers. If you want to get accurate values, you need to convert them to floating point types and then calculate.
variable
var a int = 123
a := 123
declare and assign
GO type inference
Can only be used for local variables
constant
const a int = 123
You can infer it yourself without the type.
Cannot modify
iota usage
Control constant initialization
However, using iota’s mathematical operations, including displacement operations
function
definition
keyword func
Function name
parameter list
Parameters can have names or not.
Parameters of the same type that are close together can declare their types together.
return value
Allow multiple return values
The return value can have a name, and the scope of the name is the entire function
recursion
Getting Started with Functional Styles
function as variable
local function
function as return value
anonymous function
Closure
context function
functions as types
indefinite parameters
last parameter
Equivalent to using slices
defer
First in, last out
Principles for determining values
Passed as a parameter: determined when defining
Introduced as a closure: determined when used
Modify return value
Only named return values can be modified
Implementation principle
control structure
for
for range loop
for i loop
for condition loop
switch statement
There can be a default branch
No need to break
Compilation can be switched through instructions
1
Naming rules
Capitalization controls accessibility
camel case nomenclature
Support type inference
Recommended Use