Primitive Types & Variables¶
Type declarations, conversions, zero values, and variable patterns.
Variables¶
int / float¶
str¶
bool¶
None¶
// Go has no universal "None". nil applies to specific types:
var p *int // nil pointer
var m map[string]int // nil map
var s []int // nil slice
if p == nil {
fmt.Println("no value")
}
Zero values
Go variables are initialized to their zero value automatically:
int → 0, string → "", bool → false, pointers/maps/slices → nil.
Type Conversion¶
strconv.Atoi("42") // 42, error
strconv.Itoa(42) // "42"
strconv.ParseFloat("3.14", 64) // 3.14, error
// Type casting (numeric only)
float64(42) // 42.0
int(3.14) // 3
String ↔ number requires strconv
string(65) does not give "65" — it gives "A" (the Unicode character). Use strconv.Itoa for number-to-string conversion.