Assuming that x is an integer, the construct if x: is functionally the same as if x != 0: in Python. Some languages’ style guides explicitly forbid against the former — for example, ActionScript/Flex’s style guide states that you should never implicitly cast an int to bool for this sort of thing.
Does Python have a preference? A link to a PEP or other authoritative source would be best.
The construct:
if x:is generally used to check against boolean values.For
ints the use of the explicitx != 0is preferred – along the lines of explicit is better than implicit (PEP 20 – Zen of Python).