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
%vvalue,%+vwith fields;%#vGo syntax%s,%d,%f,%t
Common errors
- Mismatched verbs and types (e.g.,
%dfor strings). Use%vas a safe default.
Practice
- Use
%+vand%#vto 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.