Go Output
Print writes values, Println adds spaces between them and a newline, and Printf formats with verbs: %v any value, %d integer, %f float, %s string, %t bool, %T type, %q quoted. Sprintf returns the text instead of printing it.
Example
fmt.Print("a", "b", 1, 2, "\n")
fmt.Println("a", "b", 1, 2)
fmt.Printf("%s is %d years old\n", "Ada", 21)
fmt.Printf("%.2f %v %t %q\n", 3.14159, []int{1, 2}, true, "hi")
s := fmt.Sprintf("%05d", 42)
fmt.Println(s)Result
ab1 2 a b 1 2 Ada is 21 years old 3.14 [1 2] true "hi" 00042
Exercise
Verb for an integer.
fmt.Printf("%", 5)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.