diff options
author | Niels Bom <niels@nielsbom.com> | 2018-12-01 05:29:58 +0100 |
---|---|---|
committer | Divay Prakash <divayprakash@users.noreply.github.com> | 2018-12-01 09:59:58 +0530 |
commit | 609abd33284284a487f1ac3bd0a6898ed6a77267 (patch) | |
tree | 7c54933931ab3ac5f1d05d4c245d2a6839ca5147 | |
parent | dd703e894ebd9019f1e009fbcff7b45d01753b0e (diff) |
[python3/en] show that True and False are ints (#3412)
* [python3/en] show that True and False are ints
* [python3/en] rework some boolean stuff
I removed the example `-5 != False != True #=> True` because we didn't cover chaining yet.
-rw-r--r-- | python3.html.markdown | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/python3.html.markdown b/python3.html.markdown index c7fbf342..b3f89372 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -72,15 +72,24 @@ not False # => True True and False # => False False or True # => True -# Note using Bool operators with ints -# False is 0 and True is 1 +# True and False are actually 1 and 0 but with different keywords +True + True # => 2 +True * 8 # => 8 +False - 5 # => -5 + +# Comparison operators look at the numerical value of True and False +0 == False # => True +1 == True # => True +2 == True # => False +-5 != False # => True + +# Using boolean logical operators on ints casts them to booleans for evaluation, but their non-cast value is returned # Don't mix up with bool(ints) and bitwise and/or (&,|) +bool(0) # => False +bool(4) # => True +bool(-6) # => True 0 and 2 # => 0 -5 or 0 # => -5 -0 == False # => True -2 == True # => False -1 == True # => True --5 != False != True #=> True # Equality is == 1 == 1 # => True |