Use FString For Formatting
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: use-fstring-for-formatting
Section titled “Sourcery refactoring id: use-fstring-for-formatting”Description
Section titled “Description”Replace calls to string.format() with f-strings.
Before
Section titled “Before”print("Good {}, {} {}".format(time_of_day, first_name, last_name))print(f"Good {time_of_day}, {first_name} {last_name}")Explanation
Section titled “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.