Use FString For Formatting¶
Sourcery refactoring id: use-fstring-for-formatting
¶
Description¶
Replace calls to string.format()
with f-strings.
Before¶
print("Good {}, {} {}".format(time_of_day, first_name, last_name))
After¶
print(f"Good {time_of_day}, {first_name} {last_name}")
Explanation¶
Python added f-strings in version 3.6, with PEP 498. F-strings are a flexible and powerful way to format strings. They make the code shorter and more readable, since the code now looks more like the output.