Go Data Types

Understanding data types is fundamental to programming as they define the kind of values a variable can hold and its size. In Go, this concept is critical because the language is statically typed. Once a variable’s type is set, it can only contain values of that type.

Tutorials dojo strip



Basic Data Types in Go

Go provides three primary types of data:

  1. Boolean (bool)
    A Boolean data type stores logical values. It can hold either true or false.
  2. Numeric
    This category includes:
    • Integer types: Whole numbers such as 10 or -45.
    • Floating point types: Decimal numbers like 3.14 or -0.987.
    • Complex types: Represents numbers with both real and imaginary parts.
  3. String (string)
    String data types are used for text values. They are sequences of characters like "Hello" or "GoLang Rules!".




Example of Go Data Types

The example below demonstrates how various data types can be used in a Go program:

Go

Output:

Go
Tutorials dojo strip