Go - Types & Keywords
Beginner 10/10
Teacher 10/10
Architect 10/10
Built-in Types
- Numbers:
int
,int64
,float64
,complex128
- Text:
string
,rune
(Unicode code point),byte
- Aggregates:
array
,slice
,map
,struct
- Others:
bool
,pointer
,interface
Zero Values and Inference
var s string // ""
var n int // 0
var f float64 // 0
var b bool // false
x := 10 // inferred int
Important Keywords
defer
,panic
,recover
go
(start goroutine),select
type
,interface
Common errors
- Mixed types in expressions without explicit conversion (e.g.,
int
+float64
). Fix by converting:float64(i) + f
. - Using
:=
at package level. Short declaration only works inside functions.
Practice
- Declare variables of types
int
,float64
, andstring
, then print them withfmt.Printf
using verbs%d
,%f
, and%q
. - Convert an
int
tofloat64
and add it to anotherfloat64
number.
Quick quiz
- What’s the zero value of
string
? - When can you use
:=
?
Show answers
- An empty string (
""
). - Inside functions when declaring a new variable.