mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-12 01:34:19 +02:00
add more details on truthiness
This commit is contained in:
@@ -144,8 +144,16 @@ None is None # => True
|
|||||||
# very useful when dealing with primitive values, but is
|
# very useful when dealing with primitive values, but is
|
||||||
# very useful when dealing with objects.
|
# very useful when dealing with objects.
|
||||||
|
|
||||||
# None, 0, and empty strings/lists all evaluate to False.
|
# Any object can be used in a Boolean context.
|
||||||
# All other values are True
|
# 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(0) # => False
|
||||||
bool("") # => False
|
bool("") # => False
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user