Golang, also called Go, is a motionless and strongly typed language. This means that every variable should have a related data type which can't be changed after declaration. Whereas variables in Go are announced through the 'var' keyword, further followed by the variable declarations through ':=' operator, where the kind is reasoned through the compiler. This blog will give a brief description on variables and data types in Go, what are variables in Go, what are data types in Go, types and more. Let's begin.

A variable is a labelled storage location in memory made use to hold a value in Go. The value can be modified throughout the program's execution. Every variable in Go has a particular data type, dictating the type of values it can store. Types of values like texts, numbers, boolean values, and then the operations which can be done on it.
Enroll in igmGuru's Golang Training Program to build career in programming language
Basically variables are the placeholders of the information that can be transformed at the running time. Variables in Go categorizes variables in different types according to the type of data they hold. Here are the types of variables in Go given below.
There are majorly 4 types of variables in Go.
The basic types speak for the fundamental data values. Here are the basic types given below.
These types blend multiple values in a single entity. Here are the aggregate types given below. Here are the aggregate types given below.
These types of variables in Go hold the references to the fundamental data structures. Here are the reference types given below.
They explain a set of method signatures, permitting variables to hold values of any kind which apply to those methods.
As a motionless typed programming language, Go differentiates data into multiple kinds, these represent the kind of values a variable can and the operations which can be done on them. Read on to know the types of data types in Go.

As data is a crucial concept in programming. It specifies the size and type of variable values. As it is a statically typed language, which means once a variable type is described, it can only preserve data of that kind. There are three basic data types in Go and they are-
Now, here is an example to make things easier for you to understand.
package main import "fmt" func main() { // Integer var num int = 25 // Float var price float64 = 19.99 // String var name string = "Go" // Boolean var isFun bool = true // Slice (dynamic array) var numbers []int = []int{1, 2, 3} // Printing values and types fmt.Println("num:", num, "(Type: int)") fmt.Println("price:", price, "(Type: float64)") fmt.Println("name:", name, "(Type: string)") fmt.Println("isFun:", isFun, "(Type: bool)") fmt.Println("numbers:", numbers, "(Type: slice)") }package main import "fmt" func main() { // Integer var num int = 25 // Float var price float64 = 19.99 // String var name string = "Go" // Boolean var isFun bool = true // Slice (dynamic array) var numbers []int = []int{1, 2, 3} // Printing values and types fmt.Println("num:", num, "(Type: int)") fmt.Println("price:", price, "(Type: float64)") fmt.Println("name:", name, "(Type: string)") fmt.Println("isFun:", isFun, "(Type: bool)") fmt.Println("numbers:", numbers, "(Type: slice)") } |
Here is the output of the code given above, when you run the program:
num: 25 (Type: int) price: 19.99 (Type: float64) name: Go (Type: string) isFun: true (Type: bool) numbers: [1 2 3] (Type: slice) |
Now, here is an explanation on the example given above:
The Integer (int) stores whole numbers (e.g., 25). Then Float (float64) stores decimal numbers (example 19.99). The String stores text (e.g 'Go'). Then the Boolean (bool) variable stores true or false. And Slice ([]int) is a flexible array which can grow for instance, [1, 2, 3].
This example keeps it simple by focusing on commonly used data types, showing their values and types in a clear and beginner-friendly way.
Read Also- Top 50+ Golang Interview Questions And Answers
As we know variables are a placeholder of the information that can be changed during runtime. They permit to Retrieve and Manipulate the stored information. There are three ways to find variable types in Go and they are -
Here is an example given below to make things easier for you to understand.
package main import ( "fmt" "reflect" ) func main() { num := 42 price := 9.99 name := "Go" // Method 1: Using fmt.Printf with %T fmt.Printf("num type: %T\n", num) fmt.Printf("price type: %T\n", price) fmt.Printf("name type: %T\n", name) // Method 2: Using reflect.TypeOf fmt.Println("num type:", reflect.TypeOf(num)) fmt.Println("price type:", reflect.TypeOf(price)) fmt.Println("name type:", reflect.TypeOf(name)) } |
Now, take a look at the output of the example given below.
num type: int price type: float64 name type: string num type: int price type: float64 name type: string |
Here is an explanation on the example given above -
It is making use of fmt.Printf with %T. Here, the %T format verb in fmt.Printf directly prints the type of a variable like int, float64, string.
Secondly it makes use of reflect.TypeOf. The reflect package's TypeOf function returns the type of a variable and is useful for programmatic type checking.
We read in this blog about the variables and data types in Go with examples to understand these in an easier way. These data types define the type of data that a valid Go variable can hold.
You can make use of typeof to check the data structure or type of a variable. It's useful in debugging while working with various data types.
It describes the exact methods that some other type should have.
If your GOPATH environment variable is not set then the default location is $HOME/go on Linux and macOS and %USERPROFILE%\go on Windows.
Understanding Go data types helps freshers store and use data correctly. It also improves code efficiency and reduces errors in programs.
Course Schedule
| Course Name | Batch Type | Details |
| Golang Training | Every Weekday | View Details |
| Golang Training | Every Weekend | View Details |