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
142
142
-----------------------------------
143
143
144
144
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.
146
148
147
149
**Bad **:
148
150
@@ -160,10 +162,14 @@ just add it to the if statement.
160
162
161
163
# Just check the value
162
164
if attr:
163
- print ' True !'
165
+ print ' attr is truthy !'
164
166
165
167
# or check for the opposite
166
168
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 :
167
173
print ' attr is None!'
168
174
169
175
Access a Dictionary Element
You can’t perform that action at this time.
0 commit comments