I've written `"text {foo}".format(foo=foo)` so many times I've almost convinced myself that it's not that verbose. Then i discovered fstrings introduced ins 3.6:
```
>>> f"text {fpp}"
'text foo'
```
>>> mind == blown
True
it is very very true. F-strings are awesome.
But there is one use case that I prefer .format(), and is when formatting a string using a dictionary. Being able to is awesome:
I've only recently started learning Python, and the f-strings remind me a bit of the syntactic sugar provided by C# for string.Format() (var str = $"Hello, my name is {name}."; // for those who care)
I get the same feeling as well, and it's something I noticed a lot when it was a new feature to C#. Suddenly, everyone abandoned string.Format() in favour of $"", even when the code would lose a lot of readability.
Syntactic sugar is good and all, but I find it better to be more verbose for the sake of clarity.
[+] [-] tedmiston|8 years ago|reply
[+] [-] tudelo|8 years ago|reply
[+] [-] pyedpiper|8 years ago|reply
[+] [-] in9|8 years ago|reply
[+] [-] EnderMB|8 years ago|reply
I get the same feeling as well, and it's something I noticed a lot when it was a new feature to C#. Suddenly, everyone abandoned string.Format() in favour of $"", even when the code would lose a lot of readability.
Syntactic sugar is good and all, but I find it better to be more verbose for the sake of clarity.
[+] [-] kristoff_it|8 years ago|reply
When you just want to interpolate a string on the fly, Fstrings are absolutely the right thing to do most of the time.
[+] [-] pyedpiper|8 years ago|reply
https://cito.github.io/blog/f-strings/
[+] [-] jxub|8 years ago|reply
[+] [-] dozzie|8 years ago|reply
[+] [-] odonnellryan|8 years ago|reply
[+] [-] mailslot|8 years ago|reply