summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
authoryihong <yihong@exmaple.com>2015-10-30 05:04:41 +0800
committeryihong <yihong@exmaple.com>2015-10-30 05:04:41 +0800
commit14c85ba0ffbb66d9c2a056006cedaa90df8f22f4 (patch)
treed57e42217f74a7727b434bbe9ac91e7c778661d5 /python.html.markdown
parente65899cafb9edbd4fbf5c37a3f6462b999bd08cb (diff)
add more details on truthiness
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown14
1 files changed, 11 insertions, 3 deletions
diff --git a/python.html.markdown b/python.html.markdown
index 42a52bcf..7055689e 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -63,7 +63,7 @@ allow you to write Python 3 code that will run on Python 2, so check out the Pyt
# to carry out normal division with just one '/'.
from __future__ import division
11/4 # => 2.75 ...normal division
-11//4 # => 2 ...floored division
+11//4 # => 2 ...floored division
# Modulo operation
7 % 3 # => 1
@@ -144,8 +144,16 @@ None is None # => True
# very useful when dealing with primitive values, but is
# very useful when dealing with objects.
-# None, 0, and empty strings/lists all evaluate to False.
-# All other values are True
+# Any object can be used in a Boolean context.
+# The following values are considered falsey:
+# - None
+# - zero of any numeric type (e.g., 0, 0L, 0.0, 0j)
+# - empty sequences (e.g., '', (), [])
+# - empty containers (e.g., {}, set())
+# - instances of user-defined classes meeting certain conditions
+# see: https://docs.python.org/2/reference/datamodel.html#object.__nonzero__
+#
+# All other values are truthy (using the bool() function on them returns True).
bool(0) # => False
bool("") # => False