Skip to content
Magenaut

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

f-string

String formatting: % vs. .format vs. f-string literal

August 22, 2022 by Magenaut

Python 2.6 introduced the str.format() method with a slightly different syntax from the existing % operator. Which is better and for what situations?

Categories Python, Q&A Tags f-string, logging, performance, python, string-formatting Leave a comment

How to postpone/defer the evaluation of f-strings?

August 20, 2022 by Magenaut

I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this:

Categories Python, Q&A Tags f-string, python, python-3.6, python-3.x, string-interpolation Leave a comment

Fixed digits after decimal with f-strings

August 19, 2022 by Magenaut

Is there an easy way with Python f-strings to fix the number of digits after the decimal point? (Specifically f-strings, not other string formatting options like .format or %)

Categories Python, Q&A Tags f-string, python, python-3.x Leave a comment

f-strings vs str.format()

August 19, 2022 by Magenaut

I’m using the .format() a lot in my Python 3.5 projects, but I’m afraid that it will be deprecated during the next Python versions because of f-strings, the new kind of string literal.

Categories Python, Q&A Tags f-string, python, python-3.x, string-formatting, string-interpolation Leave a comment

How to escape curly-brackets in f-strings?

August 17, 2022 by Magenaut

I have a string in which I would like curly-brackets, but also take advantage of the f-strings feature. Is there some syntax that works for this? Here are two ways it does not work. I would like to include the literal text {bar} as part of the string. foo = "test" fstring = f"{foo} {bar}" … Read more

Categories Python, Q&A Tags curly-braces, f-string, python, python-3.x Leave a comment

String with ‘f’ prefix in python-3.6

August 14, 2022 by Magenaut

I’m trying out Python 3.6. Going through new code, I stumbled upon this new syntax:

Categories Python, Q&A Tags f-string, python, python-3.6, scope, string-formatting Leave a comment

Nested f-strings

August 14, 2022 by Magenaut

Thanks to David Beazley’s tweet, I’ve recently found out that the new Python 3.6 f-strings can also be nested:

Categories Python, Q&A Tags f-string, python, python-3.6, python-3.x, string-formatting Leave a comment

Multiline f-string in Python

August 14, 2022 by Magenaut

I’m trying to write PEP-8 compliant code for a domestic project and I have a line with an f-string that is more than 80 characters long

Categories Python, Q&A Tags f-string, python, python-3.6, string Leave a comment

How do I convert a string into an f-string?

August 13, 2022 by Magenaut

I was reading this blog post on Python’s new f-strings and they seem really neat. However, I want to be able to load an f-string from a string or file.

Categories Python, Q&A Tags f-string, python, python-3.x, string-interpolation Leave a comment

Recent Comments

  • silverplugins217 on How to add placeholder for contact form7 for dropdown?
  • Shreyas Ikhar on How to add a custom CSS class to core blocks in Gutenberg editor?
  • Magenaut on How to call function on timer ASP.NET MVC
  • Ebaad Uddin on How to call function on timer ASP.NET MVC
  • michealSmith07 on Is there a way to dynamically refresh the less command?

Tags

.net adobe-illustrator adobe-photoshop ajax arrays asp.net asp.net-core asp.net-mvc bash c# css database django eloquent express html java javascript jquery json laravel laravel-4 laravel-5 laravel-8 linux list mongodb mongoose mysql node.js npm pandas php python python-3.x react-hooks react-native react-router reactjs redux regex sql string typescript wordpress
© 2023 Magenaut • Built with GeneratePress