If the question we asked to Python is true, we get True, if false, we get False. These are Boolean values.
There are also logical expression operators that we use with Booleans. These are "And, or, not" operators.
When the And operators is used with Boolean values, if there is even one False in the values, the result is fales.
If all booleans are true, it will output True.
The "or" operator is the opposite of the "and" operator. Its usage is a little more flexible.
If there is even one True value in an expression, the output will be True.
If the entire expression consists of false values, the output will be Fales.
The "not" operator outputs the inverse of the expression that follows it.
not Ture ==> False
not False ==> True
Logical expressions (and, or, not) used with boolean values have precedence as follows :
1) Parenthesis
2) Not
3) And
4) Or
In Python objects are deteced as True or False in the background. Objects deteced as False are : 0, None, Null values([], (), "")
Objects detected as True are 1, everything that is not false.
In the following example, value 1 is detected as True, value 0 as false.
The output will be false because the and operator is used between them.
However, because the object is used in the code The output will come as the object itself.
So the output will be 0, not flase.
'Python' 카테고리의 다른 글
Methods in Strings in Python 2 (0) | 2024.09.25 |
---|---|
Methods in Strings in Python (0) | 2024.09.24 |
Eascape Sequence Opertations in Python (0) | 2024.09.20 |
Python Print Function (0) | 2024.09.19 |
Arithmetic Operation in Python (0) | 2024.09.13 |