Go is statically typed like Java and C#, not dynamically typed like Python. Variables declare with var or short declaration := inside functions.
Basic types
int,int64,float64— numeric typesstring— UTF-8 text, immutablebool—trueorfalsebyte(alias foruint8),rune(alias forint32) — bytes and Unicode code points
Declaration styles
var count int = 10
name := "Ada" // short declaration, type inferred
var ratio float64 = 0.75
:= works inside functions only. Package-level variables need var with explicit types when inference is unavailable.
Important interview questions and answers
- Q: var vs :=?
A:varworks at package or function scope;:=is short declaration inside functions with type inference. - Q: Zero values?
A: Uninitialized variables get zero values: 0 for numbers, "" for strings, false for bool, nil for pointers/slices/maps/channels.
Self-check
- What is the zero value of an int?
- Can := be used at package level?
Pitfall: := only works inside functions—package-level variables need var, unlike short declarations at module scope in some languages.
Interview prep
- var vs :=?
varworks at package or function scope;:=is short declaration inside functions with type inference.- Zero values?
0 for numbers, "" for strings, false for bool, nil for pointers/slices/maps/channels/interfaces.