diff options
author | Marcel Ribeiro Dantas <ribeirodantasdm@gmail.com> | 2022-08-28 17:36:38 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-28 17:36:38 -0300 |
commit | e6f2e1420c9f76c0282cf50ffe01f2026cb2d92b (patch) | |
tree | cebed5476e0fc24d3861c2bc0932e40b1f77cbea /python.html.markdown | |
parent | ebb3cab2494eb392dc67008abb45af5f0711b9e8 (diff) | |
parent | 6c2c6b10760ae786621438cfd60dfd326d48be41 (diff) |
Merge pull request #4491 from smith558/patch-3
[python/en] Clarify casting and move bool() function section
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/python.html.markdown b/python.html.markdown index e8c7110a..0b115c4e 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -85,12 +85,24 @@ False - 5 # => -5 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 (&,|) +# None, 0, and empty strings/lists/dicts/tuples/sets all evaluate to False. +# All other values are True bool(0) # => False +bool("") # => False +bool([]) # => False +bool({}) # => False +bool(()) # => False +bool(set()) # => False bool(4) # => True bool(-6) # => 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(2) # => True 0 and 2 # => 0 +bool(-5) # => True +bool(2) # => True -5 or 0 # => -5 # Equality is == |