rectangletangle rectangletangle - 1 year ago 118
Python Question

Very Long If Statement in Python

I have a very long if statement in Python. What is the best way to break it up into several lines? By best I mean most readable/common.

Answer Source

According to PEP8, long lines should be placed in parentheses. When using parentheses, the lines can be broken up without using backslashes. You should also try to put the line break after boolean operators.

For example:

if (abcdefghijklmnopqrstuvwxyz > some_other_long_identifier and
    here_is_another_long_identifier != and_finally_another_long_name):
    # ... your code here ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download