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
Closures Functions in Golang
How to kill execution of goroutine?
How to use Ellipsis (...) in Golang?
How to Decode or Unmarshal bi-dimensional array of integers?
Simple function with return value in Golang
Golang HTML parser
Golang Functions Returning Multiple Values
Example: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of Slices
How to concatenate two or more slices in Golang?
Regular expression to validate the date format in "dd/mm/yyyy"