Your First Line of Go
Your First Line of Go
Here's your first Go program:
example.go
package main
import "fmt"
func main() {
fmt.Println("Welcome to Go!")
}package main declares this as a runnable program. import "fmt" loads Go's printing package so you can output text.
Every Go program starts in func main(). Everything between the curly braces runs when you hit play.
fmt.Println() prints text to the screen, followed by a new line (note the capital P, Go is case-sensitive).
>_Exercise
Exercise: Make It Speak
Add one line inside main() to make the program print:
example.go
Hello GoThat's it. One line.
Stuck? Reveal a hint to help you.
Hints (0/3)
Key Takeaway
Next UpThe four types you'll use every day.