I was studying Go language a while ago, and when I have a memorandum, I will write a memo at that time.
go is composed of units called packages, and imports and exports are performed in units of functions and variables in it. Whether it can be done is determined by the case of the letters.
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Pi) //OK
fmt.Println(math.pi) // error
}
Uppercase letters are not exported If it is lowercase, it will be exported.
Variables are declared in the form of var
You can use the walrus operator (: =) to make type inference and declare type names omitted. In that case, the declaration will be
The constant is const
var i, j int = 1, 2
test := "string" //Variable initialization with type inference
const Pi = 3.14 //Constants, in this case type inference cannot be used to initialize constants
go has a function called zero value, and if a value is not assigned with a specific type, the value is automatically assigned. Therefore, you can prevent the case where you forget to enter the value and it becomes null.
bool //zero value is false
string //zero value is""
int int8 int16 int32 int64 //zero value is 0
uint uint8 uint16 uint32 uint64 uintptr
byte //Another name for uint8
rune //Another name for int32
//Represents a Unicode code point
float32 float64
complex64 complex128
For some reason, there is a complex number in the basic type.
Type conversion is possible with
var i int = 42
var f float64 = float64(i)
var u uint = uint(f)
Recommended Posts