Skip to content

multiple-starts-ends-with (PIE810)#

Derived from the flake8-pie linter.

Fix is always available.

What it does#

Checks for startswith or endswith calls on the same value with different prefixes or suffixes.

Why is this bad?#

The startswith and endswith methods accept tuples of prefixes or suffixes respectively. Passing a tuple of prefixes or suffixes is more more efficient and readable than calling the method multiple times.


msg = "Hello, world!"
if msg.startswith("Hello") or msg.startswith("Hi"):

Use instead:

msg = "Hello, world!"
if msg.startswith(("Hello", "Hi")):