Go basics
The structure of a Go program, printing with fmt, variables, types and constants, and reading input.
About 4 hours of study
Learning objectives
- Write and run a complete program
- Choose the right types
- Read numbers, words and lines from the input
Lessons
- 1
Your first Go program
How a Go program is laid out, what package main and func main mean, how go build turns source into a program, and how to print with fmt.Println, fmt.Print and fmt.Printf.
- 2
Variables, types and constants
Declaring variables with var and :=, the basic types int, float64, string, bool, byte and rune, zero values, converting between types, and constants.
- 3
Reading input
Reading numbers and words with fmt.Scan, reading whole lines with bufio.Scanner, splitting lines with strings.Fields and converting text to numbers with strconv.Atoi.
Module practice
- Go: Say hello to a nameEasy
- Go: Print a receipt lineMedium
- Go: Format a score tableHard
- Go: Area and perimeterEasy
- Go: Convert a temperatureMedium
- Go: Split seconds into days and timeHard
- Go: Add the numbersEasy
- Go: Count lines and wordsMedium
- Go: Student averagesHard