Go Tutorials

Go Programs

Go Hello World Program


Go Hello World Program

In this tutorial, we will learn how to write a Hello World program in Go language. We will go through each statement of the program.

Go Program

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Output

Hello, World!

Working of the "Hello, World!" Program

  1. package main
    This line defines the package name. The main package is special because it defines a standalone executable program in Go.
  2. import "fmt"
    This line imports the fmt package, which contains functions for formatted I/O, including printing to the console.
  3. func main()
    This line defines the main function, where the program execution begins. In Go, the main function is the entry point of the program.
  4. {
    This opening brace marks the beginning of the main function's body.
  5. fmt.Println("Hello, World!")
    This line prints the string "Hello, World!" to the console. The Println function from the fmt package adds a new line after the text.
  6. }
    This closing brace marks the end of the main function's body.