Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello World

  • package
  • main
  • import
  • func
  • run
  • build
  • fmt
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello World")
}
go run hello_world.go
Hello World
  • main function is the entry point of every program
  • fmt.Print

Every Go program has a main file that must start with "package main" and it must have a function called main.

In order to print something to the screen we first need to import the fmt class and then inside the "main" function we can write fmt.Println("Hello World").

We save this with a .go extension. Then we can run it from the command line by typing go run and the name of your file. This will compile the code into a temporary directory and then run it.