Python Basic Tutorials 60 lessons-18th class bool type conversion "Python 18th class" bool type conversion
A few last words left yesterday about the conversion of type bool, which has one row:
BOOL (' False ')
Print the result and you will find that it is true. What is the reason.
First, because in Python, the following values are considered false:
The second and 0 figures, including 0,0.0
Third, empty string, including ', ' '
The none that represents a null value
Five, empty collection, including (), [],{}
The other values are considered true.
None is a special value in Python, which means nothing, and it is not the same as 0, null characters, False, or empty collections. About the collection, we'll talk about the following course.
So, ' False ' is a string that is not empty, and is true when converted to bool type.
The result of the same bool (") is true, and a space cannot be counted as an empty string.
BOOL (") is false.
In the IF, while and other conditional judgment statements, the judgment condition is automatically converted to bool. Like what
A = ' 123 '
If a:
Print ' This isn't a blank string '
This is a very common way of writing in programming. The effect is equal to
if BOOL (a)
Or
If a!= '