Welcome To Golang By Example

Menu
  • Home
  • Blog
  • Contact Us
  • Support this website
Menu

Format specifier for boolean or print boolean in Go (Golang)

Posted on June 20, 2020June 20, 2020 by admin

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
  • bool
  • go
  • golang
  • Follow @golangbyexample

    Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2025 Welcome To Golang By Example | Design: Newspaperly WordPress Theme