DEV Community

Discussion on: 3 Common Mistakes that Python Newbies Make

Collapse
 
vberlier profile image
Valentin Berlier • Edited

Using the expression and putting it in its own function is usually pretty clear. It lets you give a label to the condition. You can also put each comparison on its own line if the expression is too long.

def is_leap_year(year):
    return (
        year % 4 == 0
        and (
            year % 100 != 0 
            or year % 400 == 0
        )
    )

The logical operators stand out more when they're at the beginning of a line.

Thread Thread
 
migueloop profile image
Miguel Ruiz

I agree too