PY3.R1714

Consider using in

To check if a variable is equal to one of many values,combine the values into a tuple and check if the variable is contained in it instead of checking for equality against each of the values. This is faster and less verbose.

Noncompliant Code:

Copy
def fruit_is_round(fruit):
    return fruit == "apple" or fruit == "orange" or fruit == "melon"

Compliant Code:

Copy
def fruit_is_round(fruit):
    return fruit in {"apple", "orange", "melon"}

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.