Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Hello World | Getting Started
Introduction to GoLang
course content

Зміст курсу

Introduction to GoLang

Introduction to GoLang

1. Getting Started
2. Data Types
3. Control Structures
4. Functions
5. Arrays and Slices
6. Intro to Structs & Maps

book
Hello World

As a first step, we will start with the conventional "Hello World" program so that you can get acquainted with the syntax and basic structure of a Go program. Following is the code to output "Hello World" using Go:

go

index

copy
123456
package main import "fmt" func main() { fmt.Println("Hello World") }

Here main() represents a function, indicated by the keyword func before it.

Note

Keywords, also known as reserved words, are special words with predefined meanings that serve specific purposes in the language. Most of the keywords, like func itself, will be explained in detail where relevant. The keywords we will learn in this section are var and const.

func main()

Everything enclosed within the following curly braces {} is executed when the program runs. In this case, the fmt.Println statement is the first thing to execute.

go

index

copy
123
func main() { fmt.Println("Hello World") }

fmt.Println prints whatever is inside the double quotes (") to the console, which in this case is "Hello World". Textual data is always enclosed in double quotation marks (").

Note

Commas , can be used in the fmt.Println statement to output multiple pieces of numerical or textual data. Spaces are automatically added between the values.

go

index

copy
123456
package main import "fmt" func main() { fmt.Println("I have", 2, "cats at home") }

Detailed explanations of the remaining code components will be provided in later chapters as they become relevant.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2
We're sorry to hear that something went wrong. What happened?
some-alt