Skip to main content

Go Data Types

Every value in a program has a data type, and this idea matters a lot: the type tells Go what kind of value a variable holds and how much space it takes up.

Types in Go are static, so a variable keeps the type you give it and will never accept data of another type later.

The language has three basic groups of types:

  • bool - a value that is either true or false
  • Numeric - whole numbers (integers), floating-point numbers, and complex numbers
  • string - a run of characters, such as a piece of text

Example

Here is one variable from each group, with the numeric group shown as both an integer and a float:

Prompt
Declare variables of type bool, int, float32, and string. Print each with a label.
Output: Go program and captured output