File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,9 @@ Check if variable equals a constant
142142-----------------------------------
143143
144144You 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
You can’t perform that action at this time.
0 commit comments