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)