Skip to content

Files

Latest commit

 

History

History
19 lines (12 loc) · 449 Bytes

consider-using-in.md

File metadata and controls

19 lines (12 loc) · 449 Bytes

Pattern: Missing use of in (...)

Issue: -

Description

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.

Example of incorrect code:

name == 'a' or name == 'b' or name == 'c'

Example of correct code:

name in ('a', 'b', 'c')