Skip to content

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
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress