rectangletangle rectangletangle - 5 months ago 34
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

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 ...
    pass