πŸŽ“ A1Learner
πŸ”

Go Introduction

Go is a programming language for building programs. Go programs run on many kinds of computers.

A first program

The package line comes first. The import line brings in fmt for printing.

package main

import "fmt"

func main() {
	fmt.Println("My first Go program")
}

Two lines in order

Two print lines run in order. The first line prints before the second line.

package main

import "fmt"

func main() {
	fmt.Println("First line")
	fmt.Println("Second line")
}

Example

package main

import "fmt"

func main() {
	fmt.Println("Go is a programming language")
	fmt.Println("Go runs on many computers")
	fmt.Println("Go code is plain text")
}

Key points

  • Go code is plain text in a file.
  • A compiler turns Go code into a form a computer can run.
  • package main names the package that holds the program.
  • The import line brings in the fmt package for printing.
  • func main is where running starts.
  • fmt.Println prints one line of text.

In this example, three print lines run in order. The first line says Go is a programming language. The second line says Go runs on many computers. The third line says Go code is plain text.

Note

Go files use the .go ending.

Try it Yourself

Edit the code, then press Run.

Running is simulated Β· Go Playground

Exercise

Which line prints text to the screen?