Go Variables and Data Types Explained with Practical Examples
Declaring Variables in Go
var name string = "Alice"
var age int = 25
count := 10 // short variable declaration (type inferred)
Basic Data Types
- Numeric types —
int,int8/16/32/64,float32,float64 - Boolean —
bool, holdstrueorfalse - String —
string, an immutable sequence of bytes - Complex types —
complex64,complex128(rarely used)
Zero Values
Unlike some languages, Go initializes variables to a "zero value" if not explicitly assigned — 0 for numbers, "" for strings, and false for booleans.
var x int // x = 0
var s string // s = ""
var b bool // b = false
PreviousHow to Install Go on Windows, Mac, and Linux – Step-by-Step Setup
Next Understanding Control Flow: If-Else, Switch, and Loops in Go
Ready to master real-world Go skills?
Learn Go hands-on with mentor-led, live sessions.
.png)