Primitive Data Types in Go
Unlike languages like Python and Javascript, Go is statically typed. That means once a variable type is defined, the variable will only store that type of data.
Go has 3 basic types
bool
Numeric
string
Bool
To declare a variable and then initalize it, you can do it following way:
var myVar bool //type declaration
myVar = false //value initialization
var myVar2 bool = false //type declaration and initialization
There is a special short cut operator to declare and define variables in Go:
myVar := false
In the above code, using the := operator, we can directly declare and assign the variable a value. The type is automatically inferred from the value.
Integers
There are two types of integers
Signed integers
Unsigned integers
Signed integers are declared with the int prefixed keywords
var x int = 200
var y int8 = -100
There are five types of int:
int -> 32 bits for 32 bit systems and 64 bits for 64 bit systems.
int8 -> 8 bit integer storing from -128 to 127
int16 -> 16 bit integer storing from -32768 to 32767
int32 -> 32 bit integer storing from +/- 2^31
int64 -> 64 bit integer storing from +/- 2^63
You can use these keywords to define integers.
Unsigned integers can be defined using uint prefixed key
var x uint = 1200
var x uint16 = 2456
Similar to int, you have five types of uint
int -> 32 bits for 32 bit systems and 64 bits for 64 bit systems.
int8 -> 8 bit storing positive values from 0 to 2^8
int16 -> 16 bit storing positive values from 0 to 2^16
int32 -> 32 bit storing positive values from 0 to 2^32
int64 -> 64 bit storing positive values from 0 to 2^64
There are two aliases for uint8 and int32
btye -> alias for uint8
rune -> alias for int32
var m rune = -42
var n byte = 37
fmt.Println(reflect.TypeOf(m), reflect.TypeOf(n))
m will be int32 whereas n will be uint8
Float
There are two types of floats
float32 -> 32 bit float storing from -3.4e+38 to 3.4e+38
float64 -> 64 bit float storing from -1.7e+308 to 1.7e+308
The default type is float64 in case you use := for defining a variable.
x := 3.44 //float64
var y float32 = 3e+38
var y float64 = 17.323
String
Strings can be defined using the string keyword
var x string = "Hello, World!"
y := "My name is awesome!"
Complex
Go also supports complex numbers as follows
a := complex(1.2, 3.4)
var b complex128 := complex(1.2, 3.4)
c := 8 + 7i
Complex numbers is the same mathematical concept where you had a real and an imaginary number. Both the real and imaginary part are floats either float32 or float64.
Complex numbers can be either 128bit or 64bit
complex128 -> 64bit f real + 64bit imaginary
complex64 -> 32bit real + 32bit imaginary
Zero Values
Following are the zero values, which are given when variables are declared without initializing
0for numeric typesfalsefor boolean type""for strings
Null
In Golang, null is replaced with nil. We will talk more about nil when discussing pointers and interfaces.

