Example to compare Println vs Printf
Println formats using the default formats for its operands and writes to standard output. Printf formats according to a format specifier and writes to standard output.
Example
package main
import "fmt"
func main() {
a, b, c := 10, 20, 30
fmt.Println(
"(a + b = c) :", a, "+", b, "=", c,
)
fmt.Printf(
"(a + b = c) : %d + %d = %d\n", a, b, c,
)
}
Output
(a + b = c) : 10 + 20 = 30
(a + b = c) : 10 + 20 = 30
Most Helpful This Week
Create and Print Multi Dimensional Slice in Golang
How to get the current date and time with timestamp in local and other timezones ?
How to check if a string contains a white space in Golang?
How to check if a string contains a numbers in Golang?
Example Function that takes an interface type as value and pointer?
How to use wildcard or a variable in our URL for complex routing?