I can't say I like the f" syntax much. I think JS's backtick is better. Other than that, I agree, much better than % and less verbose than .format. It's just the f" or f' that doesn't sit right with me
It's consistent with other strings in Python like r-strings and the older u-strings.
Python 3's F-Strings: An Improved String Formatting Syntax
31–40 of 147 posts
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#32This is super minor but I really wish f-string formatting were the default behavior for `print` or that there were a `printf` command just for it. Typing that extra f character before the quotes is just annoying enough
It was a beautiful thing and made it possible to write the same "hello world" program in Python and BASIC:
print "hello, world"Re: Python 3's F-Strings: An Improved String Formatting Syntax
#33This is super minor but I really wish f-string formatting were the default behavior for `print` or that there were a `printf` command just for it. Typing that extra f character before the quotes is just annoying enough
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#34This reminds me of Swift's string formatting syntax: let name = "Bob" print("Hi my name is \(name)") Which I always quite liked. I found myself missing this when I moved on to Rust and Go.
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#35Squiggly heredoc is something I am unaware of in any other general programming language.
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#36The thing which annoys me most about f strings is I can't build them at runtime, which means I can't just learn/teach f strings. While I know why building f strings is forbidden (they can run arbitrary code), I'm happy to take the risk.
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#37Not mentioned in the article, but with Python 3.8, f-strings have gained the ability to print debug information using `=` specifier. name = 'world' print(f'hello {name.upper()=}') outputs: hello name.upper()='WORLD' It's small, but very useful in debugging an issue or logging something to the console. https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#38This reminds me of Swift's string formatting syntax: let name = "Bob" print("Hi my name is \(name)") Which I always quite liked. I found myself missing this when I moved on to Rust and Go.
Which is usually used for escaping characters. Like, \n for new line.
So, you may end up with code like:
print(“Hi. \nMy name is \(name).”)Re: Python 3's F-Strings: An Improved String Formatting Syntax
#39I can't say I like the f" syntax much. I think JS's backtick is better. Other than that, I agree, much better than % and less verbose than .format. It's just the f" or f' that doesn't sit right with me
Yup, especially as you often need to access dict's with foo["field"] and you get a syntax error if the f-strings is also f"". JavaScript backtick syntax doesn't lead to this extra syntactic friction.
Since this:
"this is a "regular" string"
isn't valid, then neither is this:
f"dict lookup: {d["key"]}"
However, we've talked about changing f-string parsing from a "post-process regular strings" mode, to instead having the tokenizer and parser themselves aware of f-strings. When we do that, the f-string example above will work.
(edit for formatting)
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#40I can't say I like the f" syntax much. I think JS's backtick is better. Other than that, I agree, much better than % and less verbose than .format. It's just the f" or f' that doesn't sit right with me
Then you could drop the "f" prefix. I also propose adding a "p" prefix (for "plain") to remove the f-string parsing behavior.
I talked about it at the last Python core sprint, and it only got lukewarm support, so I'm not sure I'm going to pursue it.