Skip to content

Latest commit

 

History

History
45 lines (28 loc) · 1.03 KB

2.1.md

File metadata and controls

45 lines (28 loc) · 1.03 KB

Types

Concepts

There are 26 types in golang

Basic Types

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)
}

Exercises

What happens when you add an int to a float64? What about two strings?

Tips

  • The general rule of thumb is to use sized ints for data, and int for indexing, length, and capacity.

Further Reading

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.


up -- next