Skip to content

Use Fstring For Concatenation

Sourcery refactoring id: use-fstring-for-concatenation


Use f-strings for concatenating strings instead of '+'


output = "Name: " + name + ", Age: " + age


output = f"Name: {name}, Age: {age}"


Python added f-strings in version 3.6, with PEP 498. F-strings are a flexible and powerful way to concatenate strings. They make the code shorter and more readable, since the code now looks more like the output.

This refactoring replaces string concatenations using '+' with f-strings. This will only trigger if the concatenation is a mixture of strings and calculated values.