Skip to content

Commit 7b0ee41

Browse files
author
Kenneth Reitz
committed
2 parents 94e2dbb + e9339cc commit 7b0ee41

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/writing/style.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ Check if variable equals a constant
142142
-----------------------------------
143143

144144
You don't need to explicitly compare a value to True, or None, or 0 - you can
145-
just add it to the if statement.
145+
just add it to the if statement. See `Truth Value Testing
146+
<http://docs.python.org/library/stdtypes.html#truth-value-testing>`_ for a
147+
list of what is considered false.
146148

147149
**Bad**:
148150

@@ -160,10 +162,14 @@ just add it to the if statement.
160162
161163
# Just check the value
162164
if attr:
163-
print 'True!'
165+
print 'attr is truthy!'
164166
165167
# or check for the opposite
166168
if not attr:
169+
print 'attr is falsey!'
170+
171+
# or, since None is considered false, explicity check for it
172+
if attr is None:
167173
print 'attr is None!'
168174
169175
Access a Dictionary Element

0 commit comments

Comments
 (0)