×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

How to print boolean value in Golang?

Golang | Printing Boolean Value: Here, we are going to learn how to print a given Boolean value using fmt.Printf() in Go programming language?
Submitted by IncludeHelp, on August 04, 2021 [Last updated : March 05, 2023]

Printing boolean value in Golang

Given boolean values, we have to print them.

To print a boolean value using the fmt.Printf() function – we use "%t" format specifier.

Consider the below example –

In this example, we are declaring two variables value1 and value2, and assigning them with the boolean values true and false. And, then printing them using the "%t" format specifier. Also printing the boolean results of some boolean expressions.

Golang code to print boolean value

// Golang program to print boolean values

package main

import (
	"fmt"
)

func main() {
	value1 := true
	value2 := false

	fmt.Printf("value1 = %t\n", value1)
	fmt.Printf("value2 = %t\n", value2)

	// printing boolean values
	// on evaluating boolean expressions
	fmt.Printf("10 == 20 : %t\n", 10 == 20)
	fmt.Printf("10 != 20 : %t\n", 10 != 20)
	fmt.Printf("10 < 20 : %t\n", 10 < 20)
	fmt.Printf("10 > 20 : %t\n", 10 > 20)
}

Output:

value1 = true
value2 = false
10 == 20 : false
10 != 20 : true
10 < 20 : true
10 > 20 : false



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.