compare-to-zero / C2001#

Message emitted:

"%s" can be simplified to "%s" as 0 is falsey

Description:

Used when Pylint detects comparison to a 0 constant.

Problematic code:

x = 0
y = 1

if x == 0:   # [compare-to-zero]
    print("x is equal to zero")

if y != 0:   # [compare-to-zero]
    print("y is not equal to zero")

Correct code:

x = 0
y = 1

if not x:
    print("x is equal to zero")

if y:
    print("y is not equal to zero")

Note

This message is emitted by the optional 'compare-to-zero' checker which requires the pylint.extensions.comparetozero plugin to be loaded.

Created by the compare-to-zero checker.