Go Data Types

Data types tell Go what kind of value a variable holds. Go checks types at compile time — before the program runs. This prevents many bugs that other languages only catch after the program crashes.

Categories of Data Types

Go Data Types
├── Basic Types
│   ├── Numeric
│   │   ├── Integer    (int, int8, int32, int64)
│   │   ├── Unsigned   (uint, uint8, uint32, uint64)
│   │   └── Float      (float32, float64)
│   ├── Boolean        (bool)
│   └── String         (string)
├── Composite Types
│   ├── Array
│   ├── Slice
│   ├── Map
│   └── Struct
└── Special Types
    ├── Pointer
    └── Interface

This topic covers the basic types. Composite and special types each have their own dedicated topics.

Integer Types

Integers hold whole numbers — no decimal point. Go offers several integer sizes depending on how large the number needs to be.

TypeSizeRangeUse Case
int32 or 64 bitDepends on systemGeneral purpose integer
int88 bit-128 to 127Small numbers
int1616 bit-32768 to 32767Medium small numbers
int3232 bit-2 billion to 2 billionLarger numbers
int6464 bitVery large rangeVery large numbers
uint32 or 64 bit0 and above onlyNon-negative integers
package main

import "fmt"

func main() {
    var age int = 25
    var score int32 = 980000
    var population int64 = 8000000000

    fmt.Println(age)        // 25
    fmt.Println(score)      // 980000
    fmt.Println(population) // 8000000000
}

Float Types

Float types hold numbers with decimal points.

TypeSizePrecisionUse Case
float3232 bit~6–7 decimal digitsSimple decimal values
float6464 bit~15–16 decimal digitsPrecise calculations
package main

import "fmt"

func main() {
    var price float32 = 9.99
    var distance float64 = 12345.6789012345

    fmt.Println(price)    // 9.99
    fmt.Println(distance) // 12345.6789012345
}

float64 is the default and most commonly used float type in Go. Use float32 only when memory is a concern.

Boolean Type

A boolean holds only two values: true or false. Booleans are used in conditions and decisions.

package main

import "fmt"

func main() {
    var isActive bool = true
    var isPaid bool = false

    fmt.Println(isActive) // true
    fmt.Println(isPaid)   // false
}

String Type

A string holds a sequence of characters — letters, numbers, symbols, or spaces. Strings always use double quotes in Go.

package main

import "fmt"

func main() {
    var name string = "Go Programming"
    var site string = "eStudy247"

    fmt.Println(name) // Go Programming
    fmt.Println(site) // eStudy247
}

String Operations

package main

import (
    "fmt"
    "strings"
)

func main() {
    course := "go programming"

    fmt.Println(strings.ToUpper(course))     // GO PROGRAMMING
    fmt.Println(strings.Contains(course, "go")) // true
    fmt.Println(len(course))                 // 14
}

The byte and rune Types

TypeAlias ForRepresents
byteuint8A single ASCII character (0–255)
runeint32A Unicode character (any language)
package main

import "fmt"

func main() {
    var letter byte = 'A'
    var emoji rune = '😀'

    fmt.Println(letter) // 65  (ASCII value of A)
    fmt.Println(emoji)  // 128512 (Unicode code point)
}

Default Zero Values

In Go, every variable has a default zero value if no value is assigned. This prevents the "undefined variable" errors common in other languages.

TypeZero Value
int0
float640.0
boolfalse
string"" (empty string)

Key Points

  • Go checks data types at compile time — mismatched types cause errors before running
  • Use int for most whole numbers and float64 for decimal numbers
  • Boolean values are only true or false
  • Strings use double quotes; characters use single quotes (byte/rune)
  • Every type has a default zero value — Go never leaves a variable undefined

Leave a Comment