Basic Data Types

Duration: 10 min  •  Difficulty: Easy

Go has strict basic data types (statically typed). You cannot add a number (int) with text (string) directly.

Common Types

  • bool: Boolean value, can only be true or false.
  • string: A collection of characters (text).
  • int: Whole numbers (positive/negative) without decimals.
  • float64: Decimal numbers.
  • Formatting

    When printing mixed data, we often use Printf (Print Format):

  • %T: Shows the variable's data type.
  • %v: Shows the variable's value (default format).
  • MAIN.GO
    package main
    import "fmt"
    func main() {
    var isActive bool = true
    var age int = 25
    var price float64 = 19.99
    // \n is used to create a new line (Enter)
    fmt.Printf("Type: %T, Value: %v\n", isActive, isActive)
    fmt.Printf("Type: %T, Value: %v\n", age, age)
    fmt.Printf("Type: %T, Value: %v\n", price, price)
    }