Pyrfecter logo Pyrfecter

Lint, format, and modernize your Python code to make it positively perfect.

Input
Output

Linting & Analysis

Modernize your string formatting with f-strings

Introduced in PEP-498 and first released with Python 3.6, f-strings are "formatted string literals", or "formatted strings", with a syntax like f"{variable_name}":

>>> name = "Pat"
>>> f"Hello, {name}"
Hello, Pat

For anyone coming from a JavaScript or TypeScript background, f-strings are similar to template literals, also known as template strings.

In JavaScript, a template string looks like this:

>>> const name = 'Pat'
>>> console.log(`Hello, ${name}`)
Hello, Pat

Pyrfecter uses a library called flynt to convert older string formatting syntax to f-strings, and it converts both .format() and '%s' % ...-style string formatting.

How can Python f-strings improve your code?

In lots of ways. As Real Python says:

Not only are they more readable, more concise, and less prone to error than other ways of formatting, but they are also faster!

Plus, using flynt (inside or outside of Pyrfecter) means that your code will use a single method of formatting strings, which will make your code more consistent.

So, what are you waiting for? Pyrfect those strings!