Go - Output & Printing
Beginner 10/10
Teacher 10/10
Architect 10/10
Try it: Format a string with your name and age using
fmt.Printf
and verbs %s
and %d
.fmt Basics
fmt.Print("a")
fmt.Println("a", 1)
fmt.Printf("%s %d", "n", 1)
Formatting
%v
value,%+v
with fields;%#v
Go syntax%s
,%d
,%f
,%t
Common errors
- Mismatched verbs and types (e.g.,
%d
for strings). Use%v
as a safe default.
Practice
- Use
%+v
and%#v
to print a struct and compare outputs.
Quick quiz
- What’s the difference between
Print
,Println
, andPrintf
?
Show answer
Print
writes as-is, Println
adds spaces and newline, Printf
formats with verbs.