Learn Go from Python¶
A personal, opinionated set of conspect notes for a Python developer picking up Go. The goal is to explain Go on its own terms, with short Python analogies thrown in only when they sharpen the contrast.
All material targets the current stable Go release, Go 1.26.4.
How the notes are organised¶
Each topic is a numbered folder. Inside each folder, conspects and runnable code examples share one numeric sequence so the reading order is always obvious.
Ecosystem and installation¶
- What is Go — the language, the community, the ecosystem.
- The
gocommand — every subcommand you'll touch. go tool trace— the execution tracer.- File types —
.go,_test.go,go.mod,go.sum, build constraints. - Special folders —
internal/,testdata/, conventions. - Multiple Go versions —
GOTOOLCHAIN, thegoandtoolchaindirectives. - Installation — macOS, Linux, Windows.
- Additional tools —
gopls,dlv,golangci-lint, and friends. - Demo project — a small runnable module that exercises the above.
Language basics¶
- Variables and constants —
var,:=,const, andiota. - Basic types — integers, floats, strings, booleans; no truthiness.
- Type conversions — explicit
T(x),strconv, no implicit coercion. - Operators — arithmetic, overflow, integer division; no ternary.
- Control flow —
if,for(the only loop),switch. - Functions — multiple returns, named results, variadics, first-class values.
- Errors — the
errorvalue, wrapping with%w,errors.Is/As. - Pointers —
&/*,nil,new, no pointer arithmetic. - Custom types —
typedefinitions vs aliases, underlying types. - Structs — fields, literals, zero value, embedding, tags.
- Arrays and slices — len/cap,
append, and the shared-backing gotcha. - Maps — keyed lookup, comma-ok, the nil-map trap, sets.
- Choosing a data structure — slice vs map vs struct vs custom type.
- Defer — deferred calls, LIFO order, cleanup patterns.
- Panic and recover — when to panic, recovering in deferred calls.
- Imports — import paths, aliases, blank and dot imports.
Object-oriented Go¶
- Methods — value vs pointer receivers, method sets, promotion.
- Interfaces — implicit satisfaction, polymorphism, the empty interface /
any. - Type assertions and type switches — recovering the concrete type at runtime.
- Generics — type parameters and constraints.
- OOP patterns — encapsulation, composition over inheritance, polymorphism.
Packages and modules¶
- Packages and visibility — package rules, exported vs unexported,
init. - Creating and publishing a module —
go.mod, versioning,replace, publishing. - Project layout and workspaces —
internal/,cmd/,go.work.
Concurrency¶
- Goroutines —
go, scheduling,WaitGroup, the main-exits trap. - Channels — send/receive, buffering,
close,range, deadlocks. - select — multiplexing,
default, timeouts, done-channels. - Synchronization —
Mutex,Once, atomics, the race detector. - Context — cancellation, deadlines, propagation.
- Concurrency patterns — worker pools, fan-out/fan-in, pipelines.
Source¶
- Source repository: https://github.com/oduvan/learn-go-from-python.
- Each conspect cites the official sources it consulted at the bottom of the page — typically go.dev, pkg.go.dev, or the Go specification.