Tutorials References Exercises Menu
Paid Courses

Go Data Types


Go Data Types

Data type is an important concept in programming. Data type specifies the size and type of variable values.

Go is statically typed, meaning that once a variable type is defined, it can only store data of that type.

Go has three basic data types:

  • Boolean: values contain true or false
  • Numeric: includes integer, floating point and complex values
  • String: includes strings

Example

This example shows some of the different data types in Go:

package main
import ("fmt")

func main() {
  var a bool = true     // Boolean
  var b int = 5         // Integer
  var c float32 = 3.14  // Floating point number
  var d string = "Hi!"  // String

  fmt.Println("Boolean: ", a)
  fmt.Println("Integer: ", b)
  fmt.Println("Float:   ", c)
  fmt.Println("String:  ", d)
}
Try it Yourself »

Go Exercises

Test Yourself With Exercises

Exercise:

Add the correct data type for the following variables:

package main   
import ("fmt") 
func main() { var myNum = 90 var myWord = "Hello" var myBool = true }

Start the Exercise