Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/writing/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ Check if variable equals a constant
-----------------------------------

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

**Bad**:

Expand All @@ -160,10 +162,14 @@ just add it to the if statement.

# Just check the value
if attr:
print 'True!'
print 'attr is truthy!'

# or check for the opposite
if not attr:
print 'attr is falsey!'

# or, since None is considered false, explicity check for it
if attr is None:
print 'attr is None!'

Access a Dictionary Element
Expand Down