GoGo · Lesson 1 of 8

Hello, World!

Go's Hello World is famously minimal. Package declaration, one import, one function. That's the whole language in microcosm.

Every Go file starts with a package declaration. The main package is the entry point for executables. fmt is the standard library package for formatted I/O. Every Go program that prints something will import fmt.

Go
package main

import "fmt"

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

Save as hello.go and run with go run hello.go. To compile a binary: go build hello.go, then ./hello. Go compiles fast — fast enough that go run feels instant.

Go
package main

import "fmt"

func main() {
    // Println adds a newline
    fmt.Println("Hello, World!")

    // Printf — C-style formatted output
    name := "Alice"
    age := 30
    fmt.Printf("Name: %s, Age: %d\n", name, age)

    // Sprintf — returns a string instead of printing
    s := fmt.Sprintf("Hello, %s!", name)
    fmt.Println(s)

    // %v — default format (works for anything)
    nums := []int{1, 2, 3}
    fmt.Printf("%v\n", nums)   // [1 2 3]

    // %T — type of value
    fmt.Printf("%T\n", 42)    // int
    fmt.Printf("%T\n", nums)  // []int
}
◆ Note
Go enforces that all imports are used. If you import a package and don't use it, your code won't compile. Same for declared variables — unused variables are compile errors. Go takes "clean code" literally.