Hello, World

The smallest Go program: package main, func main() and fmt.Println.

Runs in Zerethon IDE · Go 1.27 Official Go documentation ↗

A Go program is package main with a func main(). The program starts in main and ends when main returns. Everything you use from the standard library is imported by name.

main.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, World!")
	fmt.Println("Sum:", 2+3)
	fmt.Printf("%s-%s!\n", "a", "b")
}

Output

Hello, World!
Sum: 5
a-b!
  • fmt.Println separates its arguments with a space and ends with a newline; fmt.Printf prints exactly the format you give it (%s text, %d integer, %v any value).
  • Braces are required, and the opening { must be on the same line as func, if or for.
  • Every import must be used: an unused import is a compile error, not a warning.