.. _consider-ternary-expression:

consider-ternary-expression / W0160
===================================

**Message emitted:**

Consider rewriting as a ternary expression

**Description:**

*Multiple assign statements spread across if/else blocks can be rewritten with a single assignment and ternary expression*

**Problematic code:**

.. literalinclude:: /data/messages/c/consider-ternary-expression/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/c/consider-ternary-expression/good.py
   :language: python




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

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