There are 26 types in golang
string type: string
boolean type: bool
numeric types:
int
,int8
,int16
,int32
,int64
uint8
,uint16
,uint32
,uint64
float32
,float64
complex32
,complex64
Let's see some examples of types:
package main
import "fmt"
func main() {
fmt.Println("hello", true, 1, 3.4, 2+3i)
fmt.Printf("%T %T %T %T %T\n", "hello", true, 1, 3.4, 2+3i)
}
What happens when you add an int to a float64? What about two strings?
- The general rule of thumb is to use sized ints for data, and
int
for indexing, length, and capacity.
While most of the remaining types are covered in the next modules, be aware that type aliases exist. They are not covered because they are rarely used and often introduce anti-patterns.