Variables and Types
Declare with var
Name the type after the variable. Zero values apply when you omit an initializer.
package main
import "fmt"
func main() {
var name string = "Go"
var lessons int
lessons = 18
fmt.Println(name, lessons)
}
Use short declaration
Inside functions, := declares and infers the type from the value.
count := 3
ready := true
fmt.Println(count, ready)
Common basic types
int,int64,float64stringfor textboolfor true/falsebyteis an alias foruint8
Constants
Constants are declared with const and cannot change.
const MaxLessons = 20
fmt.Println(MaxLessons)
Comments
One comment per signed-in account. Comments are saved with this page’s URL.