Different format specifiers can be used to print a boolean in either bool or string.
- %t can be used to print in the boolean form
- %v will print the default string. “true” for true and “false” for false
Code:
package main
import "fmt"
func main() {
t := true
f := false
fmt.Printf("%t %t\n", t, f)
fmt.Printf("%v %v\n", t, f)
}
Output
true false
true false