Add Comparison Operators (#33117)
Add comparison boolean operators 'and', 'or', and 'not'
This commit is contained in:
committed by
Paul Gamble
parent
af3833c2a7
commit
e6b4de233a
@ -11,6 +11,35 @@ It takes one argument, `x`. `x` is converted using the standard <a href='https:/
|
|||||||
|
|
||||||
If `x` is false or omitted, this returns `False`; otherwise it returns `True`.
|
If `x` is false or omitted, this returns `False`; otherwise it returns `True`.
|
||||||
|
|
||||||
|
## Comparison Operators
|
||||||
|
|
||||||
|
There are three Boolean Operators they are `and`, `or`, and `not`.
|
||||||
|
|
||||||
|
### and
|
||||||
|
|
||||||
|
| expression | result |
|
||||||
|
| --- | --- |
|
||||||
|
| true `and` true | true |
|
||||||
|
| true `and` false | false |
|
||||||
|
| false `and` true | false |
|
||||||
|
| false `and` false | false |
|
||||||
|
|
||||||
|
### or
|
||||||
|
|
||||||
|
| expression | result |
|
||||||
|
| --- | --- |
|
||||||
|
| true `or` true | true |
|
||||||
|
| true `or` false | true |
|
||||||
|
| false `or` true | true |
|
||||||
|
| false `or` false | false |
|
||||||
|
|
||||||
|
### not
|
||||||
|
|
||||||
|
| expression | result |
|
||||||
|
| --- | --- |
|
||||||
|
| `not` true | false |
|
||||||
|
| `not` false | true |
|
||||||
|
|
||||||
## Code Sample
|
## Code Sample
|
||||||
|
|
||||||
print(bool(4 > 2)) # Returns True as 4 is greater than 2
|
print(bool(4 > 2)) # Returns True as 4 is greater than 2
|
||||||
@ -27,4 +56,4 @@ If `x` is false or omitted, this returns `False`; otherwise it returns `True`.
|
|||||||
|
|
||||||
 <a href='https://repl.it/CVCS/2' target='_blank' rel='nofollow'>Run Code</a>
|
 <a href='https://repl.it/CVCS/2' target='_blank' rel='nofollow'>Run Code</a>
|
||||||
|
|
||||||
<a href='https://docs.python.org/3/library/functions.html#bool' target='_blank' rel='nofollow'>Official Docs</a>
|
<a href='https://docs.python.org/3/library/functions.html#bool' target='_blank' rel='nofollow'>Official Docs</a>
|
||||||
|
Reference in New Issue
Block a user