Introduction
Go (also called Golang) is a fast, compiled, open-source programming language created at Google, designed to be simple to read and to handle many tasks at once with built-in concurrency.
Part of the free Go course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
By the end of this lesson you'll understand what makes Go special, you'll know what every line of a Go program does, and you'll have written and run your own first program that prints to the screen.
What You'll Learn in This Lesson
1️⃣ What is Go?
Go (also called Golang) was created at Google in 2009 to fix everyday frustrations: slow compile times, messy dependencies, and how hard it was to write programs that do many things at once. It stands on four ideas you'll feel in every project:
- • Compiled — Go translates your code straight into a single native binary (one runnable file) before it runs. There's no separate runtime to install on the machine that runs it.
- • Fast — that binary starts in milliseconds and runs close to C speeds, while the compiler itself is famously quick.
- • Simple — the whole language has only 25 keywords . There's usually one obvious way to do something, so code stays easy to read.
- • Built-in concurrency — doing many tasks at once (a web server handling thousands of users, for example) is part of the language itself via goroutines , not bolted on later.
That combination is why Go powers Docker, Kubernetes, and a huge slice of modern cloud infrastructure. In this lesson you'll start where every Go programmer starts: a tiny program that prints text. Read the worked example below first — every line is explained — then run it yourself.
2️⃣ The Four Parts of Every Go Program
Look back at that example. Every Go program you ever write has the same four building blocks, in this order:
- • package main — declares which package this file belongs to. The name main is special: it marks a program you can run (as opposed to a library other code imports).
- • import "fmt" — pulls in the fmt package (say "fumpt"), Go's standard toolkit for formatting and printing text.
- • func main() { — defines the entry point . When you run the program, Go calls main first. The opening { must sit on the same line as func main() .
- • fmt.Println(...) — the actual work. Println means "print line": it writes its values and then moves to a new line.
This next example shows the small but important differences between Println (adds a newline and spaces) and Print (adds neither). Read the comments, predict the output, then check.
Your turn. The program below works once you fill in the two blanks marked ___ . Follow the 👉 hints, then run it and compare with the expected output.
3️⃣ Running Your Code with go run
To run a Go file on your own machine, you save it (for example as main.go ) and use the go run command in your terminal. It compiles and runs the program in one step — perfect while you're learning and experimenting.
One more guided exercise to lock in the structure. Three pieces of the skeleton are missing — fill each ___ using the hints.
Mini-Challenge: Your "About Me" Card
No blanks this time — just a brief and an outline to keep you on track. Write it yourself, run it, and check your output against the example in the comments. This is exactly the kind of tiny program that builds real fluency.
Common Errors (and the fix)
- "imported and not used: fmt" — In Go an unused import is a compile error , not a warning. If you import a package you never call, delete the import. (Need it only for a side effect? Use the blank identifier: import _ "fmt" .)
- "declared and not used: x" — Same rule for variables: declaring one you never read is a compile error . Use it, or remove it. This strictness keeps dead code out of your programs.
- "expected 'package', found ..." — Every file must begin with a package line, and a runnable program needs package main . Missing it (or misspelling it) stops compilation.
- "undefined: Println" or it just won't run — Exported (callable from outside) names start with a capital letter . It's fmt.Println , never fmt.println . The capital P is what makes it public.
- "syntax error: unexpected newline ..." — The opening brace must be on the same line: write func main() { , not func main() with the { on the next line.
Pro Tips
- 💡 Let the tools format for you: run go fmt (or save in an editor with Go support) and your code is auto-formatted to the one true style — no debates.
- 💡 Use the Go Playground at go.dev/play to test snippets instantly without installing anything.
- 💡 Embrace the strictness: Go refusing to compile unused imports and variables feels picky for an hour, then quietly keeps your projects clean forever.
📋 Quick Reference — Go Basics
Concept
Go Syntax
Declare runnable package
package main
Import a package
import "fmt"
Entry-point function
func main() { }
Print a line
fmt.Println("Hello")
Print, no newline
fmt.Print("Hi")
Run a file
go run main.go
Build a binary
go build -o app
Check version
go version
Frequently Asked Questions
🎉 Lesson Complete!
- ✅ Go is compiled, fast, simple , and has built-in concurrency
- ✅ package main marks a program you can run
- ✅ import "fmt" brings in code for printing
- ✅ func main() is where every program starts
- ✅ fmt.Println prints a line; go run main.go runs your code
- ✅ Unused imports and variables are compile errors — Go keeps your code clean
- ✅ Next lesson: Variables and Data Types — store text, numbers, and true/false values
Practice quiz
Which package name marks a Go program you can run directly?
- package run
- package main
- package app
- package start
Answer: package main. package main is special: it marks a runnable program. Other names produce importable libraries.
Which function does Go call first when a program starts?
- func start()
- func init()
- func run()
- func main()
Answer: func main(). func main() is the entry point; Go calls it first in a package main program.
Which standard package provides Println for printing text?
- io
- fmt
- os
- log
Answer: fmt. fmt (say 'fumpt') is the standard library's formatting and printing package.
What does fmt.Println do after writing its values?
- Nothing extra
- Adds a newline
- Adds a tab
- Clears the screen
Answer: Adds a newline. Println means 'print line': it writes the values, then moves to a new line.
What separator does fmt.Println put between multiple values?
- A comma
- A tab
- A space
- Nothing
Answer: A space. Println inserts a single space between multiple arguments.
How do fmt.Print calls behave compared to Println?
- They add no trailing newline
- They add two newlines
- They add a tab
- They print backwards
Answer: They add no trailing newline. Print adds no automatic newline or spaces, so output continues on the same line.
What happens in Go if you import a package but never use it?
- A warning only
- Nothing
- A compile error
- It runs slower
Answer: A compile error. An unused import is a compile error in Go, which keeps code clean.
Which command compiles and runs a Go file in one step?
- go compile main.go
- go run main.go
- go exec main.go
- go start main.go
Answer: go run main.go. go run main.go compiles and runs the program in a single command.
Where must the opening brace of func main go?
- On the next line
- On the same line as func main()
- Anywhere
- It is optional
Answer: On the same line as func main(). Go requires the opening brace on the same line: func main() {, not on a new line.
Why must exported names like Println start with a capital letter?
- For speed
- It is just style
- The capital makes them public
- To save memory
Answer: The capital makes them public. A leading capital letter is what makes a name exported (callable from outside the package).
Continue this course
- Next: Variables and Data Types