True and False interpretion (#32626)
* True and False interpretion How true and false is interpreted by python. * Update index.md * Update index.md
This commit is contained in:
committed by
Parth Parth
parent
bae1bb435c
commit
4a8b643497
@ -31,7 +31,7 @@ not x | if x is false, then True, else False | (3)
|
|||||||
False
|
False
|
||||||
```
|
```
|
||||||
### `and`:
|
### `and`:
|
||||||
``
|
```
|
||||||
>>> True and False # Second argument is evaluated.
|
>>> True and False # Second argument is evaluated.
|
||||||
False
|
False
|
||||||
>>> False and True # Short-circuted at first argument.
|
>>> False and True # Short-circuted at first argument.
|
||||||
@ -47,6 +47,17 @@ not x | if x is false, then True, else False | (3)
|
|||||||
True
|
True
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## How python sees True and False
|
||||||
|
|
||||||
|
For python `True==1` and `False==0`
|
||||||
|
|
||||||
|
```python
|
||||||
|
1 and False //False
|
||||||
|
0 and 1 //False
|
||||||
|
1 and True //True
|
||||||
|
1 or 0 //True
|
||||||
|
```
|
||||||
|
|
||||||
## Other boolean-operations:
|
## Other boolean-operations:
|
||||||
|
|
||||||
These are other boolean operations which are not part of the Python language, you will have to define them yourself or use the boolean expression within the parenteses.
|
These are other boolean operations which are not part of the Python language, you will have to define them yourself or use the boolean expression within the parenteses.
|
||||||
@ -202,3 +213,4 @@ xnor ( not (x or y) or (x and y) ) | |
|
|||||||
False
|
False
|
||||||
>>> not(not(False or False) or (False and False)) # Second argument is evaluated.
|
>>> not(not(False or False) or (False and False)) # Second argument is evaluated.
|
||||||
True
|
True
|
||||||
|
```
|
Reference in New Issue
Block a user