.. _else-if-used:

else-if-used / R5501
====================

**Message emitted:**

Consider using "elif" instead of "else" then "if" to remove one indentation level

**Description:**

*Used when an else statement is immediately followed by an if statement and does not contain statements that would be unrelated to it.*

**Problematic code:**

.. literalinclude:: /data/messages/e/else-if-used/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/e/else-if-used/good.py
   :language: python




.. note::
  This message is emitted by the optional :ref:`'else_if_used'<pylint.extensions.check_elif>`
   checker which requires the ``pylint.extensions.check_elif`` plugin to be loaded.

Created by the `else_if_used <https://github.com/PyCQA/pylint/blob/main/pylint/extensions/check_elif.py>`__ checker.