Loading
0x00Lesson 1 of 6

Run your first Go program

Meet package main, the main function, and fmt.Println.

14 min 4-question quiz 1 code exercise
By the end of this lesson you can
  • Create a Go program that prints a line of text.

A Go source file declares a package. An executable starts in func main() inside package main. Import fmt to format and print values. Go keeps programs intentionally simple: names are case-sensitive, and every imported package must be used.

main.go
1package main
2
3import "fmt"
4
5func main() {
6    fmt.Println("Hello, Go!")
7}
Output
Hello, Go!

fmt.Println prints its arguments and ends with a newline. The package main declaration marks this as an executable program. The compiler checks your imports and syntax before it runs.

Key takeaways

  • Create a Go program that prints a line of text.

  • Go catches many mistakes while compiling.

  • Use small experiments to understand each new language feature.

Lesson quiz

4 questions · pass with 3 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write Go

Write Go in the editor and run it against sample input with a remote compiler. Your code is sent to Compiler Explorer to compile and run.

Exercise 1

Print a greeting

+25 XP

Complete main so the program prints exactly Hello, Go! on one line.

  • Greeting
main.go
Loading editor…

Go is compiled and run by Compiler Explorer (godbolt.org), a free public service. Your source code and test input are sent to that service.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Did you like the lesson? 😆👍
Consider a donation to support our work: