Golang Tutorial - Learn Go Programming Language
Last Updated :
12 Jul, 2025
This Golang tutorial provides you with all the insights into Go Language programming, Here we provide the basics, from how to install Golang to advanced concepts of Go programming with stable examples. So, if you are a professional and a beginner, this free Golang tutorial is the best place for your learning.
Golang, or Go Programming Language, is a statically typed and procedural programming language having syntax similar to C language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google. But they launched it in 2009 as an open-source programming language.

It provides a rich standard library, garbage collection, and dynamic-typing capability, and it also provides support for the environment to adopt patterns like dynamic languages. The latest version of the Golang is 1.20.3 released on 4th April 2023.
Prerequisites
Basic Programming Experience: Although it is not mandatory, one can easily learn Golang with any programming experience. But it is always good to have experience because it will help to know about the function.
IDE or Code Editor: Any text or code editor to write and edit codes.
Command Terminal: Go works using the terminal so any terminal is good to go.
Why to Learn Golang?
The main purpose of designing Golang was to eliminate the problems of existing languages. So let us see the problems that we are facing with Python, Java, C/C++ programming languages:
- Python: It is easy to use but slow in comparison to Golang.
- Java: It has a very complex type system.
- C/C++: It has slow compilation time as well as a complex type system.
- Also, all these languages were designed when multi-threading applications were rare, so not very effective to highly scalable, concurrent and parallel applications.
- Threading consumes 1MB whereas Goroutine consumes 2KB of memory, hence at the same time, we can have millions of goroutine triggered.
Go Programming Language Key Features
Here in this section, we have mentioned the most important Go Programming features. So, find out what Golang is becoming popular.
- Golang supports environment-adopting patterns which is very similar to dynamic languages.
- The compilation time of Golang is fast access to others.
- Support concurrency and lightweight processes.
- Golang supports Interfaces.
- Go language programming supports generic programming.
- It supports assertions.

How to Download and Install Golang
Before we begin with the installation of Go, it is good to check if it might already be installed on your System. To check if your device is preinstalled with Golang or not, just go to the Command line (For Windows, search for cmd in the Run dialog (Window + R). Now run the following command:
go version
If Golang is already installed, it will generate a message with all the details of the Golang's version available, otherwise, if Golang is not installed then an error will arise stating a Bad command or file name Before starting with the installation process, you need to download it. For that, all versions of Go for Windows are available on golang.org.

Download the Golang according to your system architecture and follow the further instructions for the installation of Golang.
Step 1: After downloading, unzip the downloaded archive file. After unzipping you will get a folder named go in the current directory.
Step 2: Now copy and paste the extracted folder wherever you want to install this. Here we are installing in C drive.
Step 3: Now set the environment variables. Right click on My PC and select
Properties. Choose the Advanced System Settings from the left side and click on Environment Variables as shown in the below screenshots.
Step 4: Click on Path from the system variables, and then click Edit. Then click New and then add the Path with bin directory where you have pasted the Go folder. Here we are editing the path C:\go\bin and clicking OK as shown in the below screenshots.
Step 5: Now create a new user variable which tells Go command where Golang libraries are present. For that click on New on User Variables as shown in the below screenshots.
Now fill the Variable name as GOROOT and Variable value is the path of your Golang folder. So here Variable Value is C:\go\. After Filling click OK.
After that Click Ok on Environment Variables and your setup is completed. Now Let's check the Golang version by using the command go version on the command prompt.
After completing the installation process, any IDE or text editor can be used to write Golang Codes and Run them on the IDE or the Command prompt with the use of command:
go run filename.go
Hello World! Program in Golang
To run a Go program you need a Go compiler. In Go compiler, first you create a program and save your program with extension .go, for example, first.go.
Go
// First Go program
package main
import "fmt"
// Main function
func main() {
fmt.Println("!... Hello World ...!")
}
Output:
!... Hello World ...!
Now we run this first.go file in the go compiler using the following command, i.e:
$ go run first.go
For more details about the different terms used in this program, you can visit Hello World! in Golang
Identifiers and Keywords
Identifiers are the user-defined name of the program components. In Go Programming language, an identifier can be a variable name, function name, constant, statement labels, package name, or types.
Example:
// Valid identifiers:
_geeks23
geeks
gek23sd
Geeks
geeKs
geeks_geeks
// Invalid identifiers:
212geeks
if
default
Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as an identifier. Doing this will result in a compile-time error. There are total 25 keywords present in the Go language as follows:

Example:
Go
// Go program to illustrate
// the use of keywords
// Here package keyword is used to
// include the main package
// in the program
package main
// import keyword is used to
// import "fmt" in your package
import "fmt"
// func is used to
// create function
func main() {
// Here, var keyword is used
// to create variables
// Pname, Lname, and Cname
// are the valid identifiers
var Pname = "GeeksforGeeks"
var Lname = "Go Language"
var Cname = "Keywords"
fmt.Printf("Portal name: %s", Pname)
fmt.Printf("\nLanguage name: %s", Lname)
fmt.Printf("\nChapter name: %s", Cname)
}
Output:
Portal name: GeeksforGeeks
Language name: Go Language
Chapter name: Keywords
Data Types
Data types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows:
- Basic type: Numbers, strings, and booleans come under this category.
- Aggregate type: Array and structs come under this category.
- Reference type: Pointers, slices, maps, functions, and channels come under this category.
- Interface type
Here, we will discuss Basic Data Types in the Go language. The Basic Data Types are further categorized into three subcategories which are:
- Numbers
- Booleans
- Strings
Numbers: In Go language, numbers are divided into three sub-categories that are:
- Integers: In Go language, both signed and unsigned integers are available in four different sizes as shown in the below table. The signed int is represented by int and the unsigned integer is represented by uint.

- Floating-Point Numbers: In Go language, floating-point numbers are divided into two categories as shown in the below table:

- Complex Numbers: The complex numbers are divided into two parts are shown in the below table. float32 and float64 are also part of these complex numbers. The in-built function creates a complex number from its imaginary and real part and in-built imaginary and real function extract those parts.

- Variable names must begin with a letter or an underscore(_). And the names may contain the letters ‘a-z’ or ’A-Z’ or digits 0-9 as well as the character ‘_’.
Geeks, geeks, _geeks23 // valid variable
123Geeks, 23geeks // invalid variable
- A variable name should not start with a digit.
234geeks // illegal variable
- The name of the variable is case sensitive.
geeks and Geeks are two different variables
- Keywords is not allowed to use as a variable name.
- There is no limit on the length of the name of the variable, but it is advisable to use an optimum length of 4 – 15 letters only.
if : It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.
Syntax:
if(condition) {
// Statements to execute if
// condition is true
}
Flow Chart:

if-else : if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.
Syntax:
if (condition) {
// Executes this block if
// condition is true
} else {
// Executes this block if
// condition is false
}
Flow Chart:

Nested if : Nested if statements mean an if statement inside an if statement. Yes, Golang allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.
Syntax:
if (condition1) {
// Executes when condition1 is true
if (condition2) {
// Executes when condition2 is true
}
}
Flow Chart:

if-else-if Ladder : Here, a user can decide among multiple options. The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.
Important Points:
- if statement can have zero or one else's and it must come after any else if's.
- if statement can have zero to many else if's and it must come before the else.
- None of the remaining else if's or else's will be tested if an else if succeeds,
- The initialization statement is optional and executes before for loop starts. The initialization statement is always in a simple statement like variable declarations, increment or assignment statements, or function calls.
- The condition statement holds a boolean expression, which is evaluated at the starting of each iteration of the loop. If the value of the conditional statement is true, then the loop executes.
- The post statement is executed after the body of the for-loop. After the post statement, the condition statement evaluates again if the value of the conditional statement is false, then the loop ends.
- break
- goto
- continue
- First, we call mul function like the normal function, i.e, mul(23, 45) and executes when the function called(Output: Result : 1035 ).
- Second, we call mul() function as a defer function using defer keyword, i.e, defer mul(23, 56) and it executes(Output: Result: 1288 ) when all the surrounding methods return.
Similar Reads
Go Tutorial Go or you say Golang is a procedural and statically typed programming language having the syntax similar to C programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language and mainly used in Google
2 min read
Overview
Go Programming Language (Introduction)Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports env
11 min read
How to Install Go on Windows?Prerequisite: Introduction to Go Programming Language Before, we start with the process of Installing Golang on our System. We must have first-hand knowledge of What the Go Language is and what it actually does? Go is an open-source and statically typed programming language developed in 2007 by Robe
3 min read
How to Install Golang on MacOS?Before, we start with the process of Installing Golang on our System. We must have first-hand knowledge of What the Go Language is and what it actually does? Go is an open-source and statically typed programming language developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but
4 min read
Hello World in GolangHello, World! is the first basic program in any programming language. Letâs write the first program in the Go Language using the following steps:First of all open Go compiler. In Go language, the program is saved with .go extension and it is a UTF-8 text file.Now, first add the package main in your
3 min read
Fundamentals
Identifiers in Go LanguageIn programming languages, identifiers are used for identification purposes. In other words, identifiers are the user-defined names of the program components. In the Go language, an identifier can be a variable name, function name, constant, statement label, package name, or type. Example: package ma
3 min read
Go KeywordsKeywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to use as an identifier. Doing this will result in a compile-time error. Example: C // Go program to illustrate the // use of key
2 min read
Data Types in GoData types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows: Basic type: Numbers, strings, and booleans come under this category.Aggregate type: Array and structs come under this category.Reference type: Pointer
7 min read
Go VariablesA typical program uses various values that may change during its execution. For Example, a program that performs some operations on the values entered by the user. The values entered by one user may differ from those entered by another user. Hence this makes it necessary to use variables as another
9 min read
Constants- Go LanguageAs the name CONSTANTS suggests, it means fixed. In programming languages also it is same i.e., once the value of constant is defined, it cannot be modified further. There can be any basic data type of constants like an integer constant, a floating constant, a character constant, or a string literal.
6 min read
Go OperatorsOperators are the foundation of any programming language. Thus the functionality of the Go language is incomplete without the use of operators. Operators allow us to perform different kinds of operations on operands. In the Go language, operators Can be categorized based on their different functiona
9 min read
Control Statements
Functions & Methods
Functions in Go LanguageIn Go, functions are blocks of code that perform specific tasks, which can be reused throughout the program to save memory, improve readability, and save time. Functions may or may not return a value to the caller.Example:Gopackage main import "fmt" // multiply() multiplies two integers and returns
3 min read
Variadic Functions in GoVariadic functions in Go allow you to pass a variable number of arguments to a function. This feature is useful when you donât know beforehand how many arguments you will pass. A variadic function accepts multiple arguments of the same type and can be called with any number of arguments, including n
3 min read
Anonymous function in Go LanguageAn anonymous function is a function that doesnât have a name. It is useful when you want to create an inline function. In Go, an anonymous function can also form a closure. An anonymous function is also known as a function literal.ExampleGopackage main import "fmt" func main() { // Anonymous functio
2 min read
main and init function in GolangThe Go language reserve two functions for special purpose and the functions are main() and init() function.main() functionIn Go language, the main package is a special package which is used with the programs that are executable and this package contains main() function. The main() function is a spec
2 min read
What is Blank Identifier(underscore) in Golang?_(underscore) in Golang is known as the Blank Identifier. Identifiers are the user-defined name of the program components used for the identification purpose. Golang has a special feature to define and use the unused variable using Blank Identifier. Unused variables are those variables that are defi
3 min read
Defer Keyword in GolangIn Go language, defer statements delay the execution of the function or method or an anonymous method until the nearby functions returns. In other words, defer function or method call arguments evaluate instantly, but they don't execute until the nearby functions returns. You can create a deferred m
3 min read
Methods in GolangGo methods are like functions but with a key difference: they have a receiver argument, which allows access to the receiver's properties. The receiver can be a struct or non-struct type, but both must be in the same package. Methods cannot be created for types defined in other packages, including bu
3 min read
Structure
Arrays
Slices
Slices in GolangSlices in Go are a flexible and efficient way to represent arrays, and they are often used in place of arrays because of their dynamic size and added features. A slice is a reference to a portion of an array. It's a data structure that describes a portion of an array by specifying the starting index
14 min read
Slice Composite Literal in GoThere are two terms i.e. Slice and Composite Literal. Slice is a composite data type similar to an array which is used to hold the elements of the same data type. The main difference between array and slice is that slice can vary in size dynamically but not an array. Composite literals are used to c
3 min read
How to sort a slice of ints in Golang?In Go, slices provide a flexible way to manage sequences of elements. To sort a slice of ints, the sort package offers a few straightforward functions. In this article we will learn How to Sort a Slice of Ints in Golang.ExampleGopackage main import ( "fmt" "sort" ) func main() { intSlice := []int{42
2 min read
How to trim a slice of bytes in Golang?In Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. The slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. In the Go slice of bytes, you ar
3 min read
How to split a slice of bytes in Golang?In Golang, you can split a slice of bytes into multiple parts using the bytes.Split function. This is useful when dealing with data like encoded strings, file contents, or byte streams that must be divided by a specific delimiter.Examplepackage mainimport ( "bytes" "fmt")func main() { // Initial byt
3 min read
Strings
Strings in GolangIn the Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where every character is represented by one or more bytes using UTF-8 Encoding. In other words, strings are the immutable chain of arbitrary bytes(including bytes
7 min read
How to Trim a String in Golang?In Go, strings are UTF-8 encoded sequences of variable-width characters, unlike some other languages like Java, python and C++. Go provides several functions within the strings package to trim characters from strings.In this article we will learn how to Trim a String in Golang.Examples := "@@Hello,
2 min read
How to Split a String in Golang?In Go language, strings differ from other languages like Java, C++, and Python. A string in Go is a sequence of variable-width characters, with each character represented by one or more bytes using UTF-8 encoding. In Go, you can split a string into a slice using several functions provided in the str
3 min read
Different ways to compare Strings in GolangIn Go, strings are immutable sequences of bytes encoded in UTF-8. You can compare them using comparison operators or the strings.Compare function. In this article,we will learn different ways to compare Strings in Golang.Examplepackage main import ( "fmt" "strings" ) func main() { s1 := "Hello" s2 :
2 min read
Pointers