bool Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/bool/ Sat, 20 Jun 2020 17:54:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 bool Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/bool/ 32 32 159787465 Format specifier for boolean or print boolean in Go (Golang) https://vikasboss.github.io/format-specifier-for-bool-golang/ https://vikasboss.github.io/format-specifier-for-bool-golang/#respond Sat, 20 Jun 2020 17:52:27 +0000 https://vikasboss.github.io/?p=2335 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”...

The post Format specifier for boolean or print boolean in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
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

The post Format specifier for boolean or print boolean in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/format-specifier-for-bool-golang/feed/ 0 2335