Add Comparison Operators (#33117)

Add comparison boolean operators 'and', 'or', and 'not'
This commit is contained in:
Muh Fachrul Razy
2018-11-01 23:15:18 +08:00
committed by Paul Gamble
parent af3833c2a7
commit e6b4de233a

View File

@ -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`.
## 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
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`.
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":rocket:") <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>