Go Basics
Print a message from main.
On this page
The concept
A runnable Go program uses package main and a main function. Import fmt for formatted input and output.
Code example
Go
package main
import "fmt"
func main() {
name := "Ada"
fmt.Println("Hello,", name)
}Output
Hello, Ada
Follow the code
Open the walkthrough to inspect the example one step at a time.
Show guided walkthrough
Guided walkthroughReady
1
package main2
import "fmt"3
func main() {4
name := "Ada"5
fmt.Println("Hello,", name)6
}Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| Declare name with inferred string type. | name = "Ada" | — | |
| Print the greeting and name with a space. | name = "Ada" | Hello, Ada |
Behind the scenes
How Go processes this code
The Go compiler builds an executable. Its runtime starts the main function in package main.