Boolean type of Python data structure (BOOL)

Source: Internet
Author: User
Boolean type
  • Boolean description
  • Judging
First, the Boolean description

Boolean values in Python are expressed using constants true and false; note case;

The types returned by comparison operators < > = = are type bool, and Boolean types are usually applied in the IF and while statements;

Note that in Python, BOOL is a subclass of int (inheriting int), so true==1 false==0 returns ture;

The true/false is not a keyword in Python2, so we can assign it arbitrarily, so the efficiency of if (true) in Python is much less efficient than if (1); True false in Python2 version is not a keyword and can be assigned to a value. Python3 will be the error;

because bool is int, it can be computed numerically, for example: print (true+true)

Second, the determination

The following values are judged to be true or false:

The number 0----------False;

Null (including empty string, empty list, empty ancestor ....) )---------False;

In addition to the above, the other expressions are judged to be True, and this needs to be noted that it is quite different from other languages.

  

Boolean type of Python data structure (BOOL)

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.