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(). When you run the program, Go executes the lines inside its curly braces from top to bottom.
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 GoStuck? Reveal a hint to help you.
Hints (0/3)
Key Takeaway
Next UpThe four types you'll use every day.