Python

Python

Made by DeepSource

Consider merging startswith/endswith checks PY-W0077

Anti-pattern
Major

The methods startswith and endswith for string instances accept two types of Python constructs as the first argument. The types are:

  • a Python string, or
  • a tuple of strings

It is recommended to merge the arguments of multiple calls to startswith/endswith connected by or.

Bad practice

if s.startswith('a') or s.startswith('b'):
    ...

Recommended

if s.startswith(('a', 'b')):
    ...