Go · Stage 9 – Organizing Bigger Programs · Lesson 52 of 64

Standard and External Imports

Import a package and use its exported names.

Go code

import "strings"

fmt.Println(strings.ToUpper("go"))
Line-by-line explanation
  1. Import makes the standard strings package available.
  2. Strings.ToUpper selects an exported function.
  3. The result is displayed.
Expected output
GO

This is the expected result.

An external package comes from another module and must be recorded as a dependency. Import only packages the file actually uses; Go rejects unused imports.