GoLang

Basic types

Go's basic types are

bool

string

int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr

byte // alias for uint8

rune // alias for int32 // represents a Unicode code point

float32 float64

complex64 complex128

The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type.

Zero values

Variables declared without an explicit initial value are given their zero value.

The zero value is:

0 for numeric types, false for the boolean type, and "" (the empty string) for strings.

Type conversions

i := 42
f := float64(i) // type converted to float64

If with a short statement

Like for, the if statement can start with a short statement to execute before the condition.

Variables declared by the statement are only in scope until the end of the if.