ADVERTISEMENT
ADVERTISEMENT

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

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.