Go language Type: Boolean type

Source: Internet
Author: User
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}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.