.. _consider-using-f-string:

consider-using-f-string / C0209
===============================

**Message emitted:**

Formatting a regular string which could be a f-string

**Description:**

*Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and ``py-version >= 3.6``.*

**Problematic code:**

.. literalinclude:: /data/messages/c/consider-using-f-string/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/c/consider-using-f-string/good.py
   :language: python

**Additional details:**

Formatted string literals (f-strings) give a concise, consistent syntax
that can replace most use cases for the ``%`` formatting operator,
``str.format()`` and ``string.Template``.

F-strings also perform better than alternatives; see
`this tweet <https://twitter.com/raymondh/status/1205969258800275456>`_ for
a simple example.


Created by the `refactoring <https://github.com/PyCQA/pylint/blob/main/pylint/checkers/refactoring/recommendation_checker.py>`__ checker.