Use f-string instead of legacy string formatting

f-string is easier to read, write, and less computationally expensive than legacy string formatting.

f-strings provide a way to embed expressions inside string literals using minimal syntax. Through this f-strings are readable, more concise, and less prone to error than other ways of formatting.

Legacy string formatting such as printf style and .format(...) are less readable than f-strings. Given that these are completely equivalent:

Why not choose the easiest to read, write, and quickest to execute (the first one)?

If our GitHub code review bot spots this issue in your pull request it gives this advice:

code-review-doctorbotsuggested changes just now
helpers.py
1
+
def get_name(user):
2
+
    return "%s %s" % (user.first_name, user.last_name)

f-string is easier to read, write, and less computationally expensive than legacy string formatting.

Read more
Suggested changes
-
    return "%s %s" % (user.first_name, user.last_name)
+
    return f'{user.first_name} {user.last_name}'
Commit suggestion
Update helpers.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.