Python Variables, Zero Values, Constants & iota
Go offers explicit variable declarations with var and type-inferred short declarations with := inside functions. Uninitialized variables automatically receive their zero value (0, "", false, nil). The iota enumerator simplifies successive integer constant definitions.
"In Go, uninitialized variables are never filled with random memory garbage: declaring a variable is like receiving a freshly cleaned whiteboard erased to 0, empty string, or false."
Deep Dive: How It Works
Short Declaration (:=): Infers type automatically at compile time (only valid inside function bodies).
Guaranteed Zero Values: int/float = 0, string = "", bool = false, pointers/slices/maps = nil.
iota Constant Generator: Automatically increments by 1 for each line in a const () block.
Syntax Blueprint
var total int = 10
count := 42 // Inferred int
const (
StatusPending = iota // 0
StatusActive // 1
)Declare explicit vars, short inferred variables, and auto-incrementing constants with iota.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using short declaration := at package global scope outside of functions.Why it happens: := is only valid inside function bodies.
How to fix: Use var name = value or var name Type at package level.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Inspect StateStopped iota Code
Print "Stopped State: %d\n" using the StateStopped constant with fmt.Printf.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.