First, the use of variables
1.1 What are variables
A variable is a name given to a memory location to store a value of a particular type. There is a variety of syntax for declaring variables in GO.
1.2 Declaring Variables
Syntax for declaring a single variable when a var name type
It must start with a letter or underscore and consists of one or more letters, digits, and underscores (_)Copy the code
In go language, the basic components of functions are: keyword func, function name, parameter list, return value, function body and return statement. Each program contains many functions, and a function is a basic code block to declare a variable
The first way is to specify the type of the variable and use the default value if no value is assigned
The second way is to determine the type of the variable based on the value
Package Go code import "FMT" func main(){/* Variable: variable concept: a small block of memory used to store data that can be changed during program execution Static languages: strongly typed languages go, Java, c++ dynamic languages: weakly typed languages JavaScript */ / Printf("%d\n",num1) var num2 int =15 fmt.Printf("%d\n",num2) // Var name=" FMT.Printf("%T %s",name,name) Short definition, Print(sum) var a,b,c int a=1 b=2 c=3 ftt. Println(a,b,c) var m,n int =100,200 FMT.Println(m,n) var n1,f1,s1=100,3.14,"go" FMT.Println(n1,f1,s1) var(studentName="李小" age=18) fmt.Println(studentName,sex,age) }Copy the code