This is a created article in which the information may have evolved or changed.
The Boolean type in the Go language is basically the same as other languages, and the keyword is bool, which can be assigned a predefined true and false example code as follows:
From http://www.cnblogs.com/osfipin/
Boolean types cannot accept other types of assignments, and automatic or forced type conversions are not supported. The following example is an incorrect usage that causes a compilation error:
var b bool B = 1//Compile error B = bool (1)//Compile error The following usage is correct: var b bool B = (1!=0)//compile the correct FMT. PRINTLN ("Result:", b)//print result is result:true
Boolean can do 3 logical operations,&& (logical AND), | | (logical OR),! (logical non).
Comparison operators: <,>, ==,!=, <=, >=.
MORE: Type introduction.
Learning Code:
Package Mainimport ("FMT" "reflect") func main () {var val1, val2 boolval1 = Falseval2 = Trueval3: = falsefmt. Println (reflect. TypeOf (VAL1))//Output boolfmt. PRINTLN (VAL2)//Output truefmt. Println (reflect. TypeOf (VAL3))//output Boolvar Val4 Boolval4 = (1! = 0) fmt. PRINTLN (VAL4)//Output True}