How to make a line break on the Python ternary operator?
Sometimes a line containing a ternary operator in Python gets too long: answer = 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel." Is there a recommended way to make a line break at 79 characters with a ternary operator? I did not find it in PEP 8 . You can always extend a logical line across multiple physical lines with parentheses: answer = ( 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel.") This is called implicit line joining . The above uses the PEP8 everything-indented-one-step